标签:
ip_spider.py= = = #!/usr/bin/python # coding: utf-8 import os import sys import requests import re import urllib import sys reload(sys) sys.setdefaultencoding( "utf-8" ) def getUrl(urlIP): url = ‘http://www.123cha.com/ip/?q=%s‘ % urlIP r = requests.get(url) reg = r‘<td class="tg-data">(.+?.)</td>‘ gre = re.compile(reg) number = re.findall(gre,r.text) print number[0] print number[2] fsock = open(‘ipaddress.txt‘, ‘a+‘) fsock.write("%s|%s\n" % (str(number[0]),str(number[2]))) if __name__ == ‘__main__‘: file_object = open(‘ipfile3‘) list_of_all_the_lines = file_object.readlines( ) # print list_of_all_the_lines for dd in list_of_all_the_lines: getUrl(‘%s‘ % dd)
标签:
原文地址:http://www.cnblogs.com/firstrate/p/4305456.html