首页 > 解决方案 > 硒 python 网页抓取

问题描述

我正在尝试遍历 42 个站点..该脚本适用于 4-5 个站点..有时 3 个站点..有些站点直到没有 15 个站点..然后我得到图片中给出的错误。

我的代码如下:

进口时间

导入请求

从硒导入网络驱动程序

网站 = []

用户 ID=[]

密码=[]

设置=[]

chrome_options = webdriver.ChromeOptions()

chrome_options.add_argument("--disable-infobars")

打印(len(站点))

打印(长度(用户 ID))

打印(长度(密码))

打印(长度(设置))

计数=5

对于范围内的 x (len(sites)):

try:

    requests.get(sites[x])

    driver = webdriver.Chrome(chrome_options=chrome_options)

    driver.get(sites[x])

    inputElement = driver.find_element_by_id("user_login")

    inputElement.send_keys(userid[x])

    inputElement = driver.find_element_by_id("user_pass")

    inputElement.send_keys(password[x])

    inputElement.submit()

    link = driver.find_element_by_id('menu-plugins')

    link.click()

    driver.find_element_by_xpath('//a[@href="'+settings[x]+'"]').click()

    driver.find_element_by_id('save_and_import').click()

    count=count+2

    time.sleep(count)

    driver.quit()

except requests.ConnectionError:

    print(sites[x]+"DOWN !!")

    continue

在此处输入图像描述

标签: pythonweb-scrapingselenium-chromedriver

解决方案


推荐阅读