我一直在使用firefox+selenium进行抓取。但是,我决定改用Phantomjs,因为它应该更快。在
在python中使用Phantomjs+ghostdriver+selenium时,添加cookie时遇到了问题。为了解决这个问题,我一直在网上寻找解决办法,但我找不到正确的解决办法。在
下面是使用的代码。在
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait # available since 2.4.0
from selenium.webdriver.support import expected_conditions as EC # available since 2.26.0
driver = webdriver.PhantomJS()
driver.get("http://kswarrants.kasikornsecurities.com/www/Tool/calculator")
driver.add_cookie({'name':'Disc', 'value':'YES','Domain':'kswarrants.kasikornsecurities.com'})
options = driver.find_elements_by_xpath('//select[@id="underling0"]/option')
收到错误消息:
^{pr2}$主要错误是“只能为当前域设置Cookies”。但是,在添加cookies之前,我已经浏览了该网站。我还注意到请求头中的主机是127.0.0.1,这是本地主机。这可能是问题的根源。有没有办法解决这个问题?如何更改请求头中的主机?提前谢谢。在
添加cookie时,需要“domain”。这是我的例子
包括添加cookie、获取cookie和删除cookie:
在步骤中添加cookie时:
您应该将关键字“domain”与小写字母“d”一起使用,而不是“domain”
相关问题 更多 >
编程相关推荐