|
发表于 2020-7-11 10:12:04
|
显示全部楼层
刚刚测试 成功爬了一次,如果又报错,说明我找的IP又失效了:
- import re
- import urllib.request
- proxy_support = urllib.request.ProxyHandler({'http':'27.43.191.134:9999'})
- opener = urllib.request.build_opener(proxy_support)
- opener.addheaders = [('User_Agent','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/22.0.1207.1 Safari/537.1')]
- urllib.request.install_opener(opener)
- html=urllib.request.urlopen('http://httpbin.org/get').read().decode('utf-8')
- #print(html)
- html=re.findall(r'"origin": "(.*?)"',html) #提取IP地址
- print(html[0])
复制代码
大致知道这样可以设置 IP 代理就行,现在网上找的 IP 没一个稳的
|
|