# 时间:2022-08-02
# 程序:python自动化:读取Excel的题目并查询
import openpyxl
import time
from selenium import webdriver
if __name__ == '__main__':
wb=openpyxl.load_workbook('XXXX.xlsx')
ws=wb.worksheets[0]
topics = []
# 输入姓名
you_name = input("请输入姓名:")
# 5000是我的excel有效数据只有5000条
for i in range(2, 5000):
name=ws.cell(i,6).value
if name == you_name:
topic = ws.cell(i,2).value
topics.append(topic)
print("查询到",len(topics),"条数据")
# 输入开始和结束
begin_topic = int(input("请输入从第几条开始:"))
end_topic = int(input("请输入从第几条结束:"))
# 查询所有题目
# 打开谷歌浏览器
driver = webdriver.Chrome(f'C:\Program Files\Google\Chrome\Application\chromedriver')
driver.get("http://www.baidu.com")
for i in range(begin_topic, end_topic):
link = f'https://www.sogou.com/web?query='+str(topics[i])
print("现在查询第"+i+"题:",str(topics[i]))
new_window='window.open("{}")'.format(link)#js函数,此方法适用于所有的浏览器
driver.execute_script(new_window)
time.sleep(1)
废话不多说,直接上代码