Python请求不使用代理

2024-09-22 16:27:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了一个简单的python脚本,使用requests模块向这个网站http://www.lagado.com/proxy-test发出请求。你知道吗

这个网站基本上告诉您请求是否使用代理。根据该网站的说法,这个请求不是通过代理,实际上是通过我的IP地址。你知道吗

代码如下:

proxiesLocal = {
   'https': proxy
}
headers = RandomHeaders.LoadHeader()
url = "http://www.lagado.com/proxy-test"
res = ''
while (res == ''):
    try:
        res = requests.get(url, headers=headers, proxies=proxiesLocal)
        proxyTest = bs4.BeautifulSoup(res.text, "lxml")
        items = proxyTest.find_all("p")
        print(len(items))
        for item in items:
            print(item.text)
        quit()
    except:
        print('sleeping')
        time.sleep(5)
        continue

假设proxy是一个type string变量,它存储代理的地址,我做错了什么?你知道吗


Tags: testcomhttpurl代理网站wwwitems