request.get(url) returns empty content

后端 未结 3 1578
时光取名叫无心
时光取名叫无心 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 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.

提交回复
热议问题