Simulating ajax request with python using requests lib

前端 未结 1 851
野性不改
野性不改 2020-12-13 00:55

Why does request not download a response for this webpage?

#!/usr/bin/python

import requests

headers={ \'content-type\':\'application/x-www-fo         


        
相关标签:
1条回答
  • 2020-12-13 01:39

    Here's the smallest working example that I can come up with:

    from requests import Session
    
    session = Session()
    
    # HEAD requests ask for *just* the headers, which is all you need to grab the
    # session cookie
    session.head('http://sportsbeta.ladbrokes.com/football')
    
    response = session.post(
        url='http://sportsbeta.ladbrokes.com/view/EventDetailPageComponentController',
        data={
            'N': '4294966750',
            'form-trigger': 'moreId',
            'moreId': '156#327',
            'pageType': 'EventClass'
        },
        headers={
            'Referer': 'http://sportsbeta.ladbrokes.com/football'
        }
    )
    
    print response.text
    

    You just weren't decoding the percent-encoded POST data properly, so # was being represented as %23 in the actual POST data (e.g. 156%23327 should've been 156#327).

    0 讨论(0)
提交回复
热议问题