python 模拟ajax查询社工库...

时间:2022-03-29 19:43:23

在windows中使用,输入有关信息查询社工库,本来是网页版的,我把ajax请求提取出来。粗略的封装下,挺好玩。

#coding:utf8
import urllib2,urllib
from BeautifulSoup import BeautifulSoup

queryword=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.text
f(queryword)