Python : Trying to POST form using requests

后端 未结 3 1318
忘掉有多难
忘掉有多难 2020-11-29 03:37

I\'m trying to login a website for some scraping using Python and requests library, I am trying the following (which doesn\'t work):

import requests
headers          


        
3条回答
  •  感情败类
    2020-11-29 03:53

    You can use the Session object

    import requests
    headers = {'User-Agent': 'Mozilla/5.0'}
    payload = {'username':'niceusername','password':'123456'}
    
    session = requests.Session()
    session.post('https://admin.example.com/login.php',headers=headers,data=payload)
    # the session instance holds the cookie. So use it to get/post later.
    # e.g. session.get('https://example.com/profile')
    

提交回复
热议问题