Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PhantomJS和Selenium返回HTML;“未找到”;页_Python_Selenium_Web Scraping_Phantomjs - Fatal编程技术网

Python PhantomJS和Selenium返回HTML;“未找到”;页

Python PhantomJS和Selenium返回HTML;“未找到”;页,python,selenium,web-scraping,phantomjs,Python,Selenium,Web Scraping,Phantomjs,我正在写一个python脚本来抓取一个网站。 我已将selenium设置为使用PhantomJS(),因为我在使用firefox读取路径变量时遇到问题。 这就是我到目前为止所做的: from selenium import webdriver driver = webdriver.PhantomJS() driver.set_window_size(1024, 768) driver.get("http://www.google.com") 我在运行时收到此错误代码: > line 58

我正在写一个python脚本来抓取一个网站。 我已将selenium设置为使用PhantomJS(),因为我在使用firefox读取路径变量时遇到问题。
这就是我到目前为止所做的:

from selenium import webdriver
driver = webdriver.PhantomJS()
driver.set_window_size(1024, 768)
driver.get("http://www.google.com")
我在运行时收到此错误代码:

> line 58, in __init__
>     desired_capabilities=desired_capabilities)   File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
> line 92, in __init__
>     self.start_session(desired_capabilities, browser_profile)   File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
> line 179, in start_session
>     response = self.execute(Command.NEW_SESSION, capabilities)   File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
> line 236, in execute
>     self.error_handler.check_response(response)   File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
> line 163, in check_response
>     raise exception_class(value) selenium.common.exceptions.WebDriverException: Message: <!DOCTYPE HTML
> PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.
> org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Not Found</TITLE> <META
> HTTP-EQUIV="Content-Type" Content="text/html;
> charset=us-ascii"></HEAD> <BODY><h2>Not Found</h2> <hr><p>HTTP Error
> 404. The requested resource is not found.</p> </BODY></HTML>
>第58行,在__
>所需的\u功能=所需的\u功能)文件“C:\Python27\lib\site packages\selenium\webdriver\remote\webdriver.py”,
>第92行,in_uuuinit__
>self.start\u会话(所需的\u功能、浏览器\u配置文件)文件“C:\Python27\lib\site packages\selenium\webdriver\remote\webdriver.py”,
>第179行,在启动会话中
>response=self.execute(Command.NEW_SESSION,capabilities)文件“C:\Python27\lib\site packages\selenium\webdriver\remote\webdriver.py”,
>第236行,执行中
>self.error\u handler.check\u响应(response)文件“C:\Python27\lib\site packages\selenium\webdriver\remote\errorhandler.py”,
>第163行,在check_响应中
>引发异常\u类(值)selenium.common.exceptions.WebDriverException:消息:PUBLIC“-//W3C//DTD HTML 4.01//EN”http://www.w3.
>org/TR/html4/strict.dtd“>未找到HTTP-EQUIV=“Content Type”Content=“text/html;
>charset=us ascii“>未找到
HTTP错误 > 404. 找不到请求的资源。


不确定到底发生了什么。。还有其他人遇到过这个问题并有解决方案吗?

您使用的是什么
phantomjs
版本?phantomjs--version命令的输出是什么?它是版本2.1.1!好的,
selenium
软件包版本怎么样?那将是通过
pip
安装的
3.0.1
。我使用的是Python2.7 BTWW您使用的是什么
phantomjs
version?phantomjs--version命令的输出是什么?它是版本2.1.1!好的,
selenium
软件包版本怎么样?那将是通过
pip
安装的
3.0.1
。顺便说一句,我正在使用python 2.7