import urllib.request
import socket
import random
User_Agent = ['Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0',
"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 LBBROWSER",
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; QQBrowser/7.0.3698.400)',
'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)',
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; 360SE)',
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; SV1; QQDownload 732; .NET4.0C; .NET4.0E; SE 2.X MetaSr 1.0)',
'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.11 (KHTML, like Gecko) Chrome/17.0.963.84 Safari/535.11 SE 2.X MetaSr 1.0',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)',
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; WOW64; Trident/5.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E)'
]
shareUrl = 'http://ip.chinaz.com/getip.aspx'
proxy = {'http':'106.120.78.129:80'}
try:
#proxy_support=urllib.request.ProxyHandler({'http':proxy})
proxy_support=urllib.request.ProxyHandler(proxy)
opener = urllib.request.build_opener(proxy_support)
random_userAget = random.choice(User_Agent)
req = urllib.request.Request(shareUrl)
req.add_header("User-Agent", random_userAget)
res = urllib.request.urlopen(req).read().decode("utf8")
print (res)
except Exception as e:
print (e)
1
cat9life 2016-11-24 16:12:55 +08:00
不是高匿代理?
|
2
a329377653 OP @cat9life 是要换个高匿的代理才可以吗?,试了下换个 还是显示本机地址。。
|
3
SharkIng 2016-11-24 16:42:23 +08:00
不是全局代理吧?或者说代理设定的 route 并没有把 chinaz 的网站包含进代理路线
|
4
langmoe 2016-11-24 16:43:59 +08:00
你把浏览器重启试一下?这站 keep-alive 的时间似乎非常的长,可能你换代理之后浏览器依然使用了首次直连建立的 socket
|
5
a329377653 OP @langmoe 我用上面的程序 run 的应该跟我浏览器没关系吧? 换了几个 proxy 试试,返回的 res 还是同一个。。
|
6
langmoe 2016-11-24 16:54:19 +08:00
@a329377653 120.52.72.56:80 试试这个
curl http://ip.chinaz.com/getip.aspx -x 'http://120.52.72.56:80' {ip:'120.52.72.56',address:'北京市 联通云 BGP 数据中心'} 我这儿是没显示本机的 |
7
jiedreambuilder 2016-11-24 16:58:20 +08:00
|
8
7654 2016-11-24 16:58:24 +08:00 1
虽然你定义了代理,但是你使用了代理吗
opener req |
9
a329377653 OP 原来缺少了一句 感谢各位大锅帮助 结帖
|
10
jiedreambuilder 2016-11-24 17:02:55 +08:00
点 [这里](url "http://ip.chinaz.com/getip.aspx")
|
11
a329377653 OP @7654 是的 少了设置 ( ꒪Д꒪)ノ
|