Python_ip代理
Posted For_elegant
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python_ip代理相关的知识,希望对你有一定的参考价值。
#encoding=utf8
import urllib
import urllib2
import sys
sys.path.append(‘D:/python/beautifulsoup‘)
sys.path.append(‘C:/Python27/Lib/site-packages‘)
from bs4 import BeautifulSoup
import MySQLdb
import re
print sys.getdefaultencoding()
User_Agent = ‘Mozilla/5.0 (Windows NT 6.3; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0‘
header = {}
header[‘User-Agent‘] = User_Agent
url = ‘http://www.xicidaili.com/nn/1‘
req = urllib2.Request(url,headers=header)
res = urllib2.urlopen(req).read()
soup = BeautifulSoup(res)
ips = soup.findAll(‘tr‘)
#print ips
f = open("proxy.txt","w")
for x in range(1,len(ips)):
ip = ips[x]
tds = ip.findAll("td")
#print tds
ip_temp = tds[1].contents[0]+"\t"+tds[2].contents[0]+"\n"
print ip_temp
#print tds[2].contents[0]+"\t"+tds[3].contents[0]
f.write(ip_temp)
f.close()
以上是关于Python_ip代理的主要内容,如果未能解决你的问题,请参考以下文章