python爬取头条好货广告_python多线程爬取-今日头条的街拍数据(附源码加思路注释)...

本文介绍了如何使用Python结合requests、BeautifulSoup和多线程库来爬取今日头条上的街拍数据。通过定义不同的函数实现网页索引获取、页面解析、详情页数据抓取以及图片下载,并对爬取到的街拍图片进行存储。
摘要由CSDN通过智能技术生成

这里用的是json+re+requests+beautifulsoup+多线程

1 importjson2 importre3 from multiprocessing.pool importPool4

5 importrequests6 from bs4 importBeautifulSoup7 from config import *

8 from requests importRequestException9

10

11 defget_page_index(offset, keyword):12 '''得到一个页面的索引'''

13 data ={14 'offset': offset,15 'format': 'json',16 'keyword': keyword,17 'autoload': 'true',18 'count': '20',19 'cur_tab': '1',20 'from': 'search_tab'

21 }22 #请求方式一

23 #url = 'https://www.toutiao.com/search_content/?'+urlencode(data)

24 #response = requests.get(url)

25

26 #请求方式二

27 url = 'https://www.toutiao.com/search_content/'

28 try:29 response = requests.get(url, params=data)30 if respons

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值