网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

pythonurl采集

python利用百度做url采集
python url采集
pip install tableprint
paramiko==2.0.8
语法:python url_collection.py -h输出帮助信息
python url_collection.py 要采集的信息 -p 页数 -t 进程数 -o 保存的文件名以及格式
新建文件touch url_collection.py
写入代码正式部分

成都创新互联是一家专业提供松溪企业网站建设,专注与成都做网站、网站设计、H5开发、小程序制作等业务。10年已为松溪众多企业、政府机构等服务。创新互联专业网络公司优惠进行中。

#coding: utf-8
import requests
from bs4 import BeautifulSoup as bs
import re
from Queue import Queue
import threading
from argparse import ArgumentParser
logo="""
u u l | ccccc ooooo l l eeeeee cccccc ttttttt
u u r rr l | c o o l l e c t
u u r r r l | c o o l l eeeeee c t
u u r l | c o o l l e c t
u u u r l | c o o l l e c t
uuuuuuuu u r lllll | ccccc ooooo llllll lllll eeeeee cccccc t
By : Snow wolf
"""
print(logo)
arg = ArgumentParser(description='baidu_url_collect py-script by snowwolf')
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='outfile', default='result.txt')
result = arg.parse_args()
headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0'}

class Bd_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_collect(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})
        for bq in bqs:
            r = requests.get(bq['href'], headers=headers, timeout=3)
            if r.status_code == 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))

for 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()

代码结束


新闻标题:pythonurl采集
当前地址:http://bjjierui.cn/article/ijscic.html

其他资讯