爬取猫咪交易网

爬取猫咪品种,价格等在售数据

代码展现:

具体代码:

import requests

import re

import os

filename = '声音//'

if not os.path.exists(filename):

os.mkdir(filename)

def down_load(page):

for page in range(page):

page = page+1

url = 'https://www.tosound.com/search/word-/page-'+str(page)

headers = {'User-Agent':

'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36',

}

response = requests.get(url=url,headers=headers)

print(response.text)

href = re.findall('<div class="ui360 ui360-vis"><a href="(.*?)"></a></div>',response.text)

title = re.findall('<a class="h6 text-white font-weight-bold" target="_blank" href=".*?" title="(.*?)">.*?',response.text)

for href,title in zip(href,title):

print(title,href)

content = requests.get(url=href,headers=headers).content

with open(filename+title+'.mp4',mode='wb') as f:

f.write(content)

down_load(4)

结果展现:

反思与总结:1.如何用正则匹配html中换行的数据,如

我想要匹配电话,却总是空,把上面的连在一起匹配,也是一样,是换行符的问题吗?

2.像这种抓爬静态页面,零碎的信息,用css选择器更好!

3.这一案例属于两静态 页面抓取,信息都在页面代码中,抓包容易,难点在于如何解析数据。

相关推荐
跟橙姐学代码12 分钟前
Python 类的正确打开方式:从新手到进阶的第一步
前端·python·ipython
c8i12 分钟前
关于python中的变量中使用的下划线_总结
python
站大爷IP20 分钟前
用Flet打造跨平台文本编辑器:从零到一的Python实战指南
python
MC皮蛋侠客33 分钟前
使用python test测试http接口
开发语言·python·http
胡耀超1 小时前
5、Python-NumPy科学计算基础
开发语言·人工智能·python·深度学习·numpy
BIGSHU09232 小时前
java多线程场景3-并发处理和异步请求
java·开发语言·python
Source.Liu2 小时前
【Python自动化】 21.3 Pandas Series 核心数据结构完全指南
python·自动化·pandas
Sirius Wu2 小时前
私有化部署Ragflow的预训练模型
人工智能·python·语言模型·火山引擎
Mr_sun.2 小时前
Day04_苍穹外卖——套餐管理(实战)
开发语言·python
南棱笑笑生3 小时前
20250910在荣品RD-RK3588-MID开发板的Android13系统下修改短按power按键的休眠/唤醒为关闭/打开背光
开发语言·python·rockchip