Pythons请求使用selenium打开浏览器的会话

时间:2016-02-21 23:28:36

标签: python selenium selenium-webdriver beautifulsoup python-requests

我希望使用requests.sessionbeautifulsoup。如果识别出503的特定状态,则我想在Web浏览器中打开该会话。问题是我不知道如何使用selenium将python请求会话移动到浏览器中。任何指导都将不胜感激。

1 个答案:

答案 0 :(得分:0)

请求会话具有可用于导入Selenium的CookieJar个对象。例如:

driver = webdriver.Firefox()
s = requests.Session()
s.get('http://example.com')

for cookie in s.cookies:
    driver.add_cookie({
        'name': cookie.name, 
        'value': cookie.value,
        'path': '/'
        'domain': cookie.domain
    })

driver现在应该拥有请求所具有的所有Cookie(以及会话)。