#!user/bin/python
#coding:utf-8
import urllib
import urllib2
import re
import random
ip_list = ['61.163.163.145:9999', '111.161.126.90:8080']
def fetch_file(path):
with open(path, 'r') as f:
gjc = f.readlines()
f.close()
return gjc
def search_char(content):
result = []
for item in content:
ip = random.choice(ip_list)
k = urllib.quote(item.decode('gbk').encode('utf-8'))
url = 'http://sug.so.360.cn/suggest?callback=suggest_so&encodein=utf-8&encodeout=utf-8&format=json&fields=word,obdata&word=' + k
headers = {
"GET": url,
"Host": "zhidasug.www.so.com",
"Referer": "http://www.so.com/",
"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36"
}
proxy_handler = urllib2.ProxyHandler({'http': 'http://' + ip})
opener = urllib2.build_opener(proxy_handler)
urllib2.install_opener(opener)
req = urllib2.Request(url)
for key in headers:
req.add_header(key, headers[key])
html = urllib2.urlopen(req).read()
result.append(html)
return result
def display(result):
reg = re.compile(r'"word":"(.*?)"')
for dic in result:
for word in re.findall(reg, dic):
print word
if __name__ == '__main__':
path = "C:\Users\Administrator\Desktop\you.txt"
content = fetch_file(path)
result = search_char(content)
display(result)
浏览器关键字。
最新推荐文章于 2022-10-06 20:01:39 发布