|
|
10鱼币
- import urllib.request
- ##该网址用来测试来源ip是什么
- url = 'http://www.whatismyip.com.tw'
- ##1 ip+port
- proxy_support = urllib.request.ProxyHandler({'http:':'89.188.242.191:8080'})
- ##2
- '''
- ##修改header,防止被禁止
- opener = urllib.request.build_opener(proxy_support)
- '''
- opener = urllib.request.build_opener(proxy_support)
- ##代理还是采用百度翻译
- opener.add_header = [('User-Agent','Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER')]
- ##3
- urllib.request.install_opener(opener)
- ##4
- response = urllib.request.urlopen(url)
- html = response.read().decode('utf-8')
- print(html)
复制代码 |
最佳答案
查看完整内容
http://bbs.fishc.com/forum.php?mod=redirect&goto=findpost&ptid=74280&pid=2620904
|