已解决(selenium模块操作浏览器报错)selenium.common.exceptions.TimeoutException: Message: script timeout


文章目录

  • 报错代码
  • 报错翻译
  • 报错原因
  • 解决方法
  • 千人全栈VIP答疑群联系博主帮忙解决报错

报错代码

粉丝群里面的一个粉丝用selenium模块操作浏览器爬取网页数据,但是发生了报错(跑来找我求助,然后顺利帮助他解决了,顺便记录一下希望可以帮助到更多遇到这个bug不会解决的小伙伴),报错信息和代码如下:

chrome_options.add_argument('--proxy-server=http://%s' % proxies['http'])  # 添加代理
# chrome_options.add_argument('--headless')
# chrome_options.add_argument('--disable-gpu')
# 添加请求头伪装浏览器
chrome_options.add_argument('user-agent=%s' % random.choice(ua_list))
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(20)
# 启动浏览器,获取网页源代码
driver = webdriver.Chrome(chrome_options=chrome_options)with open(r'E:\Python\stealth.min.js') as f:js = f.read()driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {"source": js
})driver.get(url)
html_str = driver.page_source
print(html_str)
# 翻页
for i in range(2, 20):page = str(i)# print(html_str)js = "pageSkip('%s')" % pagedriver.execute_script(js)time.sleep(10)html_str = driver.page_source

报错信息截图如下所示

报错翻译

报错信息翻译

硒。超时异常:消息:脚本超时

报错原因

报错原因

跟等待时间挂钩的,然后就是元素定位问题,所以问题可能出在定位元素找不到上了。小伙伴按下面的方式解决即可!!!

解决方法

1. 浏览器元素加载的等待时间设置久一点:

driver.implicitly_wait(60)

2. Selenium希望在异步脚本完成后触发回调。如果没有返回任何内容,则脚本超时开始并抛出一个错误,重复运行:

try:js = "pageSkip('%s')" % pagedriver.execute_script(js)time.sleep(10)html_str = driver.page_sourceget_data(html_str, page)time.sleep(30)except:js = "pageSkip('%s')" % pagedriver.execute_script(js)time.sleep(10)html_str = driver.page_sourceget_data(html_str, page)time.sleep(30)

以上是此问题报错原因的解决方法,欢迎评论区留言讨论是否能解决,如果有用欢迎点赞收藏文章谢谢支持,博主才有动力持续记录遇到的问题!!!

千人全栈VIP答疑群联系博主帮忙解决报错

由于博主时间精力有限,每天私信人数太多,没办法每个粉丝都及时回复,所以优先回复VIP粉丝,可以通过订阅限时9.9付费专栏《100天精通Python从入门到就业》进入千人全栈VIP答疑群,获得优先解答机会(代码指导、远程服务),白嫖80G学习资料大礼包,专栏订阅地址:https://blog.csdn.net/yuan2019035055/category_11466020.html

  • 优点:作者优先解答机会(代码指导、远程服务),群里大佬众多可以抱团取暖(大厂内推机会),此专栏文章是专门针对零基础和需要进阶提升的同学所准备的一套完整教学,从0到100的不断进阶深入,后续还有实战项目,轻松应对面试!

  • 专栏福利:简历指导、招聘内推、每周送实体书、80G全栈学习视频、300本IT电子书:Python、Java、前端、大数据、数据库、算法、爬虫、数据分析、机器学习、面试题库等等

  • 注意:如果希望得到及时回复,订阅专栏后私信博主进千人VIP答疑群

免费资料获取,更多粉丝福利,关注下方公众号获取

已解决selenium.common.exceptions.TimeoutException: Message: script timeout相关推荐

  1. 已解决selenium.common.exceptions.TimeoutException: Message:

    已解决(selenium爬虫报错)selenium.common.exceptions.TimeoutException: Message: 文章目录 报错代码 报错翻译 报错原因 解决方法 千人全栈 ...

  2. 已解决selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary

    已解决selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary ...

  3. 已解决selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted:

    已解决python selenium模块自动化操作浏览器点击元素,抛出异常selenium.common.exceptions.ElementClickInterceptedException: Me ...

  4. 已解决 selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element 找不到元素的问题

    场景 使用selenium的find_element_by_xpath()函数报错:selenium.common.exceptions.NoSuchElementException: Message ...

  5. 已解决 selenium.common.exceptions.NoSuchWindowException: Message: no such window

    D:\学习\Python工程\venv\Scripts\python.exe "D:\软件\PyCharm Community Edition 2019.1.3\plugins\python ...

  6. 已解决selenium.common.exceptions.WebDriverException: Messag: ‘geckodriver‘ executable needs to be in PA

    已解决selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in P ...

  7. 解决selenium.common.exceptions.WebDriverException: Message: unknown error: call function result missin

    (Session info: chrome=73.0.3683.103)(Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32 ...

  8. selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate elemen

    selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate elemen ...

  9. 解决selenium用cookies时候报错selenium.common.exceptions.InvalidArgumentException: Message: invalid argument

    报错如下: selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid 'xxxxx ...

最新文章

  1. 写一个会导致死锁的线程
  2. Miniconda3及pip换源(conda清华源关闭)
  3. Python 装饰器 函数
  4. Vmware 连接局域网通过桥接方式
  5. 目标检测再次革新!图灵奖得主团队提出Pix2Seq,将Detection变成了Image Captioning...
  6. Vista工具箱 v3.1
  7. 微软或将全资收购 GitHub,价格达 50 亿美元或更高
  8. python无限弹窗1.0
  9. HBuilder开发app,扫描枪中,使用input输入框,然后点击扫描,获取不到条码!
  10. 最佳和最快的游戏 DNS 服务器
  11. 推荐18个非常棒的Web和移动开发框架
  12. 3.4.7nbsp;安迪·格鲁夫
  13. 2108 JAVASE每日复习总结 链接汇总
  14. 打印机如何双面打印、复印?
  15. 74HC595级联电路篇(二)
  16. PHP实现页面静态化页面
  17. git clone时提示,git remote: HTTP Basic: Access denied 错误
  18. 好多人一个月3000块钱工资怎么维持生活的?
  19. 7类AI淘金者:各显神通,但钱到底被谁赚了?
  20. 向量空间搜索引擎理论

热门文章

  1. 情感成熟的20个标志,你知道吗?
  2. Python程序设计实例:可查询修改、添加、测验、朗读的英语词典
  3. inprivate浏览是什么意思_InPrivate浏览是什么?各大浏览器如何开启InPrivate浏览
  4. $.getJSON( )的使用方法简介
  5. 做双线策略路由用的网通ip段
  6. 基于JAVA房屋租赁网站计算机毕业设计源码+系统+lw文档+部署
  7. LeetCode 二叉树专题 (1)二叉树知识 和 解题框架
  8. 【牛客刷题】前端面试必备——HTML
  9. join()方法作用
  10. 为什么me域名不能备案_.me域名是否能注册,能不能备案?