首页 > 解决方案 > Python selenium webdriver什么也没得到,但浏览器通常会显示网页

问题描述

源代码:

from selenium import webdriver
browser = webdriver.Safari()
html_doc = browser.get("http://www.google.com")
#html_doc is empty but the Safari window shows the page normally
#Allow Remote Automation is enabled

这是我第一次使用Selenium,一开始它工作正常,用html_doc正常获取内容,然而,问题发生在几个小时后,重启Python和重启计算机都没有工作。感谢您的任何建议!

标签: pythonseleniumsafarigetwebdriver

解决方案


browser.get不返回任何东西,这就是为什么html_doc是空的。如果你想要你需要使用的页面源page_source

browser.get("http://www.google.com")
html_doc = browser.page_source

推荐阅读