亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

python采集百度搜索結(jié)果帶有特定URL的鏈接代碼實(shí)例

 更新時(shí)間:2019年08月30日 10:24:47   作者:linyouyi  
這篇文章主要介紹了python采集百度搜索結(jié)果帶有特定URL的鏈接代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下

這篇文章主要介紹了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í)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python面向?qū)ο缶幊讨惖倪M(jìn)階

    Python面向?qū)ο缶幊讨惖倪M(jìn)階

    這篇文章主要介紹了Python面向?qū)ο缶幊讨惖囊茫?Reference是對象的指針,引用是內(nèi)存中真實(shí)對象的指針,表示為變量名或者內(nèi)存地址、每個(gè)對象存在至少一個(gè)引用,id()函數(shù)用于獲得引用,想具體了解的小伙伴可以參考下面文章的內(nèi)容
    2021-11-11
  • 最新評論