request.get(url) returns empty content

后端 未结 3 1493
时光取名叫无心
时光取名叫无心 2020-12-04 02:31

I am trying to figure this out, but had no luck:

import requests
r = requests.get(\'http://example.com/m7ppct4\', allow_redirects=True)

相关标签:
3条回答
  • 2020-12-04 02:50
    import requests
    import json
    import pprint
    
    
    r = requests.get('URL')
    pprint.pprint(json.loads(r.content))
    
    0 讨论(0)
  • 2020-12-04 03:00

    You must send any user agent:

    import requests
    r = requests.get('http://example.com/m7ppct4',  headers={'User-Agent':'test'})
    
    0 讨论(0)
  • 2020-12-04 03:16

    It looks like the website linked by tinyurl (azstatejobs) filters requests based on user-agents. Spoofing the Chrome user-agent worked for me:

    import requests
    url = 'http://tinyurl.com/m7ppct4'
    user_agent = 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.143 Safari/537.36'
    headers = {'User-Agent': user_agent}
    r = requests.get(url, headers=headers)
    

    (allow_redirect is true by default)

    You might want to try different user-agents and see what makes that website not like the python requests user-agent.

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