Use existing authenticated session from browser to perform https request on python

后端 未结 3 1876
清歌不尽
清歌不尽 2021-02-15 10:55

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

3条回答
  •  难免孤独
    2021-02-15 11:35

    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)
    

提交回复
热议问题