python 刷访问量_python刷知乎访问量

#coding=utf-8

importrandomimporturllib2importtimefrom lxml importetree

url= "http://www.xicidaili.com/"header_list=['Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)',"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1",'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',"Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50"]'''随机选择一个user-agent 与下面拼接'''header_one=random.choice(header_list)

header={'User-Agent': header_one,

}'''最好先进入西刺网站,然后copy 一个ip 地址。如果使用自己的ip 小心被封!!'''httpproxy_handler= urllib2.ProxyHandler({"HTTPS": "60.177.229.9:18118"})

opener=urllib2.build_opener(httpproxy_handler)

request= urllib2.Request(url, headers=header)

urllib2.install_opener(opener)

data=urllib2.urlopen(request).read()

content=etree.HTML(data)

url_list= content.xpath('//tr/td[2]/text()') #解析地址

port = content.xpath('//tr/td[3]/text()') #解析端口号

text = content.xpath('//td[6]/text()') #解析地址类型!

d=list()

li=list()

dir=dict()for i in range(50, len(url_list)):

li.append(url_list[i]+ ":" +port[i])for j inrange(len(url_list)):

d.append(text[j])for i in range(1,len(url_list)): #第一个url 开始!

#print({text[i]: li[i]})

'''每次的地址进行提取!'''httpproxy_handler=urllib2.ProxyHandler({text[i]: li[i]})

url_list=['''这是放置url的地方!''']

list=['Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0)',"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0;","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.163 Safari/535.1",'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0) Gecko/20100101 Firefox/6.0','Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50',"Opera/9.80 (Windows NT 6.1; U; zh-cn) Presto/2.9.168 Version/11.50"]whileTrue:#通过 urllib2.build_opener()方法使用这些代理Handler对象,创建自定义opener对象

header_one =random.choice(list)

url_one=random.choice(url_list)

header={'User-Agent': header_one,}

opener=urllib2.build_opener(httpproxy_handler)print(str({text[i]: li[i]}) + "\t" + str(url_one) + "\t" + str(header_one) + "正在读取!")

request= urllib2.Request(url_one, headers=header)

time.sleep(10)

urllib2.install_opener(opener)

response=urllib2.urlopen(request).read()print("结束!")break

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值