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

后端 未结 3 1507
礼貌的吻别
礼貌的吻别 2021-02-15 11:17

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:50

    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)
    

提交回复
热议问题