python多线程爬取大量数据_python使用多线程爬取数据

本文介绍了如何使用Python进行网页爬取,首先展示了单线程爬取数据的方式,然后通过引入多线程,显著提高了爬取效率。在多线程实现中,创建了多个线程并行执行爬取任务,最终结果显示,多线程爬取相比单线程在相同任务下节省了大约30%的时间。
摘要由CSDN通过智能技术生成

1.使用普通方式爬取

#!/usr/bin/python3

#coding:utf8

from bs4 import BeautifulSoup

import requests

import time

from concurrent.futures import ProcessPoolExecutor

from threading import Thread

url='http://www.kan12345.com/class.asp?id=27&page='

w=open('ut','w')

#w=open('ut','r+')

#w.read()

def get(url):

req=requests.Session()

html=req.get(url)

#html=html.content.decode("gb2312")

soup=BeautifulSoup(html.text,'html.parser')

ss=soup.find_all('div',class_='box')

soup=BeautifulSoup(str(ss),'html.parser')

ss=soup.find_all('h4')

soup=BeautifulSoup(str(ss),'html.parser')

ss=soup.find_all('a')

print(url)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值