Reputation: 1395
Im looking to use requests.session
and beautifulsoup
. If a specific status of 503 is identified I want to then open that session in a web browser. The problem is I have no idea how to move a python requests session into a browser using selenium. Any guidance would be appreciated.
Upvotes: 0
Views: 3487
Reputation: 431
Requests sessions have CookieJar objects that you can use to import into Selenium.
For example:
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
should now have all of the cookies (and therefore sessions) that Requests has.
Upvotes: 2