Is it possible to take an existing logged in session (say in Chrome) and pipe that session to a python script to perform an https request?
To be clear on what I want to
This should be possible if you reuse your browser's cookies and user agent. As far as I can see, any such solution would be browser-specific though: I have come across a script that uses SQLite to extract Chrome cookies and use them to make HTTP requests with the Requests
library.
The script's chrome_cookies
method returns a dictionary containing cookies. If you use the Requests
library, you can pass the dictionary as a keyword argument when making requests:
import requests
import pyCookieCheat
url = 'http://www.example.com'
s = requests.Session()
cookies = pyCookieCheat.chrome_cookies(url)
s.get(url, cookies = cookies)
Why don't you parse out the generated CAPTCHA, display the image and manually input the solution? It may be an easier approach to your problem than actually hijacking a session. Plus, it would result in a more portable and stable script (probably).
This might help
jar = requests.cookies.RequestsCookieJar([
{
"domain": ".stackoverflow.com",
"expirationDate": "1427212131.77312",
"hostOnly": "false",
"httpOnly": "true",
"name": "usr",
"path": "/",
"secure": "false",
"session": "false",
"storeId": "0",
"value": "SOMEVALUE",
"id": "5"
}]
requests.get(url, headers=headers, cookies=jar)
@Stupid.Fat.Cat Let me know what worked for you