#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]+" "+tds[2].contents[0]+"
"
print ip_temp
#print tds[2].contents[0]+" "+tds[3].contents[0]
f.write(ip_temp)
f.close()