1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
import time import requests import json import base64
print("使用前请参考 https://hunter.qianxin.com 语法进行检索") print("默认 page_size 为100\n")
keyword = input("请输入要检索的关键词:") keyword = base64.urlsafe_b64encode(keyword.encode("utf-8")) apikey = ""
def search(keywords): page = 0 num = 0 while True: try: page += 1 url = "https://hunter.qianxin.com/openApi/search?api-key={}&search={}&page={}&page_size=100&is_web=1&status_code=200".format(apikey, keywords.decode(), page) r = requests.get(url, timeout=3) res = json.loads(r.text) loadurl = res['data']['arr'] for i in loadurl: num += 1 print(i['url']) with open("hunterurl.txt", "a+") as f: f.write(i['url'] + "\n") time.sleep(0.06) except Exception as e: print("\n") print("采集完成,共采集{}条Url".format(num)) break
if __name__ == '__main__': search(keyword)
|