Python Requests - Use navigate site by servers IP

后端 未结 4 2028
生来不讨喜
生来不讨喜 2021-01-03 02:20

I want to crawl a site, however cloudflare was getting in the way. I was able to get the servers IP, so cloudflare won\'t bother me.

How can I utilize this in the re

4条回答
  •  攒了一身酷
    2021-01-03 02:55

    You will have to set a custom header host with value of example.com, something like:

    requests.get('http://127.0.0.1/foo.php', headers={'host': 'example.com'})
    

    should do the trick. If you want to verify that then type in the following command (requires netcat): nc -l -p 80 and then run the above command. It will produce output in the netcat window:

    GET /foo.php HTTP/1.1
    Host: example.com
    Connection: keep-alive
    Accept-Encoding: gzip, deflate
    Accept: */*
    User-Agent: python-requests/2.6.2 CPython/3.4.3 Windows/8
    

提交回复
热议问题