简体   繁体   English

Python Selenium Webdriver什么也没得到,但浏览器通常显示该网页

[英]Python selenium webdriver gets nothing but the browser normally shows the webpage

Source Code: 源代码:

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

This is the first time I use Selenium, at first it worked normally, with html_doc normally gets the content, however, the problem occurred several hours later, and neither restart Python nor restart the computer worked. 这是我第一次使用Selenium,起初它可以正常工作,而html_doc通常可以获取内容,但是,问题在几个小时后发生,并且既没有重新启动Python也没有重新启动计算机。 Thanks for any suggestions! 感谢您的任何建议!

browser.get doesn't return anything, that's why html_doc is empty. browser.get不返回任何内容,这就是html_doc为空的原因。 If you want the page source you need to use page_source 如果您想要页面源,则需要使用page_source

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM