【发布时间】:2016-06-19 15:16:57
【问题描述】:
我有一个可以正常调用网页的对象,即使使用add_cookie。但是,我想渲染一个大量使用 angularjs 的网站。出于某种原因,我似乎无法设置正确的 cookie,这是我从实时会话中提取的。因此,我不确定其中有多少是我弄错的 cookie-foo,以及我缺少多少需要发生的 angular-js-foo。如果人们在这里有意见,那就太好了,但即使是 cmets 指出我去哪里摄取也会有帮助,因为我自己并没有走得太远。我已经清除了以下值。甚至一些关于如何调试的指针。我的目标是在页面上呈现divs。
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from bs4 import BeautifulSoup
class WebPage():
def __init__(self):
dcap = dict(DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = (
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/53 "
"(KHTML, like Gecko) Chrome/15.0.87"
)
self.driver = webdriver.PhantomJS(desired_capabilities=dcap, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
self.driver.set_window_size(1024, 768)
def get_page(self):
url = "http://proadvisor.intuit.com/search/index-standalone.html?v2#/search-result?location=60613&distance=500"
self.driver.get(url)
cookie = {'aam_aud': 'a_value', 'ttax': 0}
self.driver.add_cookie(cookie)
page = BeautifulSoup(self.driver.page_source, "lxml")
page.find_all("div")
if __name__ == '__main__':
wp = WebPage()
wp.get_page()
现在得到:
selenium.common.exceptions.WebDriverException: Message: Error Message => 'Can only set Cookies for the current domain' 由 Request => {"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"104"," Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:34940","User-Agent":"Python-urllib/3.3"},"httpVersion":"1.1 ","method":"POST","post":"{\"cookie\": {\"aam_aud\": \"a_value\", \"ttax\": 0}, \"sessionId\": \"A-hash\"}","url":"/cookie","urlParsed":{"anchor":"","query":"","file":"cookie","directory": "/","path":"/cookie","relative":"/cookie","port":"","host":"","password":"","user":"", "userInfo":"","authority":"","protocol":"","source":"/cookie","queryKey":{},"chunks":["cookie"]},"urlOriginal ":"/session/a_hash/cookie"}
【问题讨论】:
标签: angularjs python-3.x cookies selenium-webdriver phantomjs