python采集百度搜索結(jié)果帶有特定URL的鏈接代碼實(shí)例
這篇文章主要介紹了python采集百度搜索結(jié)果帶有特定URL的鏈接代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
#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標(biāo)簽的鏈接 for bq in bqs: r = requests.get(bq['href'], headers=headers, timeout=3)#獲取真實(shí)鏈接 if r.status_code == 200:#如果狀態(tài)碼為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() #執(zhí)行格式 python aaaaa.py "inurl:asp?id=" -p 30 -t 30
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python使用Selenium自動(dòng)進(jìn)行百度搜索的實(shí)現(xiàn)
- Python通過tkinter實(shí)現(xiàn)百度搜索的示例代碼
- Python爬蟲爬取百度搜索內(nèi)容代碼實(shí)例
- python+selenium實(shí)現(xiàn)自動(dòng)化百度搜索關(guān)鍵詞
- python實(shí)現(xiàn)百萬答題自動(dòng)百度搜索答案
- python實(shí)現(xiàn)提取百度搜索結(jié)果的方法
- Python實(shí)現(xiàn)抓取百度搜索結(jié)果頁的網(wǎng)站標(biāo)題信息
- Python10行代碼實(shí)現(xiàn)模擬百度搜索的示例
相關(guān)文章
python讀取mat文件生成h5文件的實(shí)現(xiàn)
這篇文章主要介紹了python讀取mat文件生成h5文件的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07Python實(shí)現(xiàn)生成密碼字典的方法示例
這篇文章主要介紹了Python實(shí)現(xiàn)生成密碼字典的方法,結(jié)合實(shí)例形式詳細(xì)分析了Python密碼字典的實(shí)現(xiàn)方法及相關(guān)操作注意事項(xiàng),涉及字符串運(yùn)算、文件讀寫等相關(guān)操作技巧,需要的朋友可以參考下2019-09-09Python如何實(shí)現(xiàn)機(jī)器人聊天
這篇文章主要介紹了Python如何實(shí)現(xiàn)機(jī)器人聊天,幫助大家更好的理解和學(xué)習(xí)python,感興趣的朋友可以了解下2020-09-09Python MySQL 日期時(shí)間格式化作為參數(shù)的操作
這篇文章主要介紹了Python MySQL 日期時(shí)間格式化作為參數(shù)的操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-03-03如何用tempfile庫創(chuàng)建python進(jìn)程中的臨時(shí)文件
這篇文章主要介紹了如何用tempfile庫創(chuàng)建python進(jìn)程中的臨時(shí)文件,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2021-01-01使用Python為Excel文件添加預(yù)設(shè)和自定義文檔屬性
向Excel文件添加文檔屬性是專業(yè)地組織和管理電子表格數(shù)據(jù)的關(guān)鍵步驟,這些屬性,如標(biāo)題、作者、主題和關(guān)鍵詞,增強(qiáng)了文件的元數(shù)據(jù),使得在大型數(shù)據(jù)庫或文件系統(tǒng)中跟蹤變得更加容易,本文將介紹如何使用Python高效地為Excel文件添加文檔屬性,需要的朋友可以參考下2024-05-05