Python requests, change IP address

后端 未结 2 827
离开以前
离开以前 2020-12-30 16:56

I am coding a web scraper for the website with the following Python code:

import requests

def scrape(url):
    req = requests.get(url)
    with open(\'out.h         


        
相关标签:
2条回答
  • 2020-12-30 17:40

    You can use a proxy with the requests library. You can find some free proxies at a couple different websites like https://www.sslproxies.org/ and http://free-proxy.cz/en/proxylist/country/US/https/uptime/level3 but not all of them work and they should not be trusted with sensitive information.

    example:

    proxy = {
        "https": 'https://158.177.252.170:3128',
        "http": 'https://158.177.252.170:3128' 
    }
    response=requests.get('https://httpbin.org/ip', proxies=proxy)
    
    0 讨论(0)
  • 2020-12-30 17:42

    As already mentioned in the comments and from yourself, changing the IP could help. To do this quite easily have a look at vpngate.py:

    https://gist.github.com/Lazza/bbc15561b65c16db8ca8

    An How to is provided at the link.

    Have fun

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