赞
踩
- import requests
-
- proxies = {
- "http": "http://10.10.1.10:3128",
- "https": "http://10.10.1.10:1080",
- }
-
- r = requests.get('https://www.baidu.com/',proxies=proxies)
- print(r.text) # 打印返回内容
注意:代理ip可能会失效
访问:
http://httpbin.org/ip
- import requests
-
-
- r = requests.get('http://httpbin.org/ip')
- print(r.text) # 打印返回内容
设置响应超时,超时则跑出异常。
- import requests
-
- #测试http代理ip和端口(测试https在字典中修改)
- ip = '181.115.168.99'
- port = '53281'
-
- proxies = {
- "http": "http://"+ip+':'+port
- }
- try:
- r = requests.get('https://www.baidu.com/',proxies=proxies,timeout=1)
- except:
- pass
- else:#没发生异常,则打印代理ip
- print(ip+':'+port)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。