Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 2.7 Python 2.7、Selenium和PhantomJS错误_Python 2.7_Selenium_Phantomjs - Fatal编程技术网

Python 2.7 Python 2.7、Selenium和PhantomJS错误

Python 2.7 Python 2.7、Selenium和PhantomJS错误,python-2.7,selenium,phantomjs,Python 2.7,Selenium,Phantomjs,我安装了Selenium v2.7和PhantomJS v2.1。PhantomJS在我的命令提示符下运行,但在我的程序中不起作用 from selenium import webdriver driver = webdriver.PhantomJS() driver.add_cookie({'PHPSESSID': '<mysessionid>'}) driver.get("http://csgodouble.com/") print(driver.find_element_b

我安装了Selenium v2.7和PhantomJS v2.1。PhantomJS在我的命令提示符下运行,但在我的程序中不起作用

from selenium import webdriver
driver = webdriver.PhantomJS()

driver.add_cookie({'PHPSESSID': '<mysessionid>'})
driver.get("http://csgodouble.com/")

print(driver.find_element_by_xpath('//div[@class="past"]').text)
print driver.current_url
从selenium导入webdriver
driver=webdriver.PhantomJS()
添加cookie({'PHPSESSID':''})
驱动程序。获取(“http://csgodouble.com/")
打印(driver.find_element_by_xpath('//div[@class=“pass”]”)text)
打印driver.current\u url
当我运行程序时,它会输出错误:

driver=webdriver.PhantomJS()

AttributeError:“module”对象没有属性“PhantomJS”


我该如何解决这个问题?谢谢,

您的前两行代码基本上很好,但据我所知,2012年12月,PhantomJS支持没有添加到Selenium Python中

因此,如果
pip
说您有
selenium
模块的2.7.0版(从2011年9月开始),您需要做的就是升级到最新版本(2.52.0)

pip卸载selenium


然后:
pip安装-U selenium
()

您可以运行
pip list | grep selenium
?还有,
phantomjs
在你的路径上吗?@AndrewRegan我在Windows8.1上,没有grep。PhantomJS在我的Pathk上,您从
pip列表中获得的selenium版本(我应该说这对我很有用)我有selenium(2.7.0)和Python 2.7