在windows中使用,輸入有關信息查詢社工庫,本來是網頁版的,我把Ajax請求提取出來。粗略的封裝下,挺好玩。
#coding:utf8import urllib2,urllibfrom BeautifulSoup import BeautifulSoupqueryWord=raw_input(u"輸入查詢的字符串:/n".encode('gbk'))def f(queryword): q=lambda x:urllib.quote(x.decode('gbk').encode('utf8')) url="http://shegongku.org/passwd/index.php/Index/search/key/%s/vcode/" req=urllib2.Request(url%q(queryword)) req.add_header("User-Agent",r"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36") req.add_header("X-Requested-With",r'xmlHttPRequest') res=urllib2.urlopen(req) dom=BeautifulSoup(res.read()) table=dom.find("table") trs=table.findAll("tr") for tr in trs[2:]: print tr.textf(queryword)
新聞熱點
疑難解答