Python3 / Windows10 / PyCharm / Selenium / Chrome
您好,我试图在Chrome中打开一个标签页,导航至bing,搜索一个词,打开一个新标签页,导航至bing,然后搜索其他术语。
我在一个excel文件中保存了数百个搜索词,我试图自动(按组)从该电子表格中进行搜索,但是担心我的代码可能无法缩放到该数量。
任何建议,我们将不胜感激:)
print ("Hello, world!")
from selenium import webdriver
import time
driverwebdriver.Chrome(r"C:\Users")
#search term 1 denver broncos
#this opens chrome, navigates to bing, searches for "denver broncos"
driver.get("https://bing.com/")
driver.find_element_by_name("q").send_keys("denver broncos")
driver.find_element_by_name("go").click()
driver.switch_to.window(driver.window_handles[0])
#driver.implicitly_wait(3)
#search term 2 mad men
#this creates a new tab
driver.execute_script("window.open('https://www.bing.com', 'new window')")
driver.switch_to.window(driver.window_handles[1])
#driver.execute_script("window.open('https://bing.com/')")
driver.find_element_by_name("q").send_keys("mad men")
driver.find_element_by_name("go").click()
#driver.implicitly_wait(3)
#search term 3 old enlish sheepdog
#this creates a new "pop out tab", and searches for "old englsh sheepdog"
driver.execute_script("window.open('https://www.bing.com',
'https://www.bing.com', 'new window')")
driver.switch_to.window(driver.window_handles[2])
driver.find_element_by_name("q").send_keys("old english sheepdog")
driver.find_element_by_name("go").click()
#driver.implicitly_wait(3)
#search term 4 phish fall 97 tour
# this gets this error code
driver.execute_script("window.open('https://www.bing.com',
'https://www.bing.com','https://www.bing.com', 'new window')")
driver.switch_to.window(driver.window_handles[3])
driver.find_element_by_name("q").send_keys("phish fall 97 tour")
drive r.find_element_by_name("go").click()
#driver.implicitly_wait(3)
print("Code Complete!")
感谢您的帮助,我是全新的:)