#!/usr/bin/python
# -*- encoding: utf-8 -*-
import requests,re
from time import time,sleep
from sys import argv
from threading import Thread
def geturl(content,num=100):
url = "https://www.baidu.com/s?" #使用百度搜索
threadlist = [] #线程列表
headers = {
'User-Agent': r'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36'
} #设置head浏览器标识
name = argv[0][:-9]+str(time())+'.txt'
global f
f = open(name, 'a') #将获取的url写入文件
print("正在采集url,并写入文件...")
length = range(int(num/10))
for n in length: #实现翻页功能
page = n*10
thread = Thread(target=writefile,args=(url,page,headers,content))
threadlist.append(thread)
for i in length:
threadlist[i].start()
sle
python多线程实现百度url采集
最新推荐文章于 2023-06-24 13:42:25 发布