首先python安装selenium,命令行中输入

pip install selenium

在执行代码如下代码时出现错误

driver=webdriver.PhantomJS()

错误如下

selenium.common.exceptions.WebDriverException: Message: 'phantomjs' executable needs to be in PATH. 

解决方案:

问题没有下载PhantomJS,PhantomJS不需要像python模块那样安装,直接进入官网下载页面http://phantomjs.org/download.html下载相应版本安装即可。

装好解压后,把文件夹bin中的phantomjs.exe移到python安装路径文件夹中的Scripts中,至此,就已经在Win的环境下配置好了环境。

错误解决

 

获取cookie完整代码如下#将cookie写入cookie.txt文件中

from selenium import webdriver
import pickle
driver=webdriver.PhantomJS()
driver.get(url)  #此处url填写需要访问的地址
# 获得 cookie信息
cookie_list = driver.get_cookies()
print (cookie_list)
cookie_dict = {}
for cookie in cookie_list:
#写入文件
f = open('cookie.txt','wb+')
pickle.dump(cookie, f)
f.close()
   
cookie_dict[cookie['name']] = cookie['value']
 

 

有不懂的地方或者想要探讨问题可以qq联系:1163949417

相关文章:

  • 2021-07-17
  • 2021-12-16
  • 2022-12-23
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-07-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-21
  • 2021-12-17
  • 2022-12-23
  • 2021-11-08
  • 2021-10-01
  • 2021-11-04
相关资源
相似解决方案