url = 'http://www.xicidaili.com/nn/1' req = urllib2.Request(url,headers=header) res = urllib2.urlopen(req).read()
soup = BeautifulSoup.BeautifulSoup(res) ips = soup.findAll('tr') f = open("test.txt","w")
for x in range(1,len(ips)): ip = ips[x] tds = ip.findAll("td") ip_temp = tds[1].contents[0]+"\t"+tds[2].contents[0]+"\n" # print tds[2].contents[0]+"\t"+tds[3].contents[0] f.write(ip_temp)
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
#从IP池中取出IP和接口 host=[] port=[] proxys=[] #从IP池中取出IP和接口 with open('test.txt','r') as f0: for i in f0: tmp=i.split() host.append(tmp[0]) port.append(tmp[1])