python - 硒 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
解决方案
推荐阅读
- java - 如何编译和运行带参数的 Java 程序
- sql - 根据引用它的最新订单对产品进行排序 - PostgreSQL
- c - 在C中替换字符串前缀的正确方法
- python - 在使用文件访问时尝试更改对象中的某些值
- python - 安装 YOLOv5 依赖项——torchvision?
- r - 新列包含来自其他 2 列的最少数据
- javascript - 打开新标签页、刷新或关闭浏览器时如何管理 localStorage 和/或 sessionStorage?
- java - 如何在适用于 Android 10+ 的 android studio 中保存 PDF 文档
- python - 在数据框中查找所有匹配的键和值
- javascript - 未捕获的类型错误:无法使用复选框读取 app.js:2 处的 null 属性“addEventListener”