python采集百度搜索结果带有特定URL的链接
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python采集百度搜索结果带有特定URL的链接,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1673字,纯文字阅读大概需要3分钟。
内容图文
![python采集百度搜索结果带有特定URL的链接](/upload/InfoBanner/zyjiaocheng/837/59e60b086b3f484393a0ae722ee5da85.jpg)
#coding utf-8 import requests from bs4 import BeautifulSoup as bs import re from Queue import Queue import threading from argparse import ArgumentParser arg = ArgumentParser(description='baidu_url_collet py-script by xiaoye') arg.add_argument('keyword',help='keyword like inurl:?id=for searching sqli site') arg.add_argument('-p','--page',help='page count',dest='pagecount',type=int) arg.add_argument('-t','--thread',help='the thread_count',dest='thread_count',type=int,default=10) arg.add_argument('-o','--outfile',help='the file save result',dest='oufile',type=int,default='result.txt') result = arg.parse_args() headers = {'User-Agent':'Mozilla/5.0(windows NT 10.0 WX64;rv:50.0) Gecko/20100101 Firefox/50.0'} class Bg_url(threading.Thread): def __init__(self,que): threading.Thread.__init__(self) self._que = que def run(self): while not self._que.empty(): URL = self._que.get() try: self.bd_url_collet(URL) except Exception,e: print(e) pass def bd_url_collect(self, url): r = requests.get(url, headers=headers, timeout=3) soup = bs(r.content, 'lxml', from_encoding='utf-8') bqs = soup.find_all(name='a', attrs={‘data-click‘:re.compile(r'.'), 'class':None})#获得从百度搜索出来的a标签的链接 for bq in bqs: r = requests.get(bq['href'], headers=headers, timeout=3)#获取真实链接 if r.status_code == 200:#如果状态码为200 print r.url with open(result.outfile, 'a') as f: f.write(r.url + '\n') def main(): thread = [] thread_count = result.thread_count que = Queue() for i in range(0,(result.pagecount-1)*10,10): que.put('https://www.baidu.com/s?wd=' + result.keyword + '&pn=' + str(i)) or i in range(thread_count): thread.append(Bd_url(que)) for i in thread: i.start() for i in thread: i.join() if __name__ == '__main__': main() #执行格式 python aaaaa.py "inurl:asp?id=" -p 30 -t 30
内容总结
以上是互联网集市为您收集整理的python采集百度搜索结果带有特定URL的链接全部内容,希望文章能够帮你解决python采集百度搜索结果带有特定URL的链接所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。