爬取猫咪交易网

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

代码展现:

具体代码:

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.这一案例属于两静态 页面抓取,信息都在页面代码中,抓包容易,难点在于如何解析数据。

相关推荐
雨夜的星光4 小时前
Python JSON处理:load/loads/dump/dumps全解析
开发语言·python·json
fen_fen5 小时前
Java打包时,不将本地Jar打包到项目的最终 JAR 中
开发语言·python·pycharm
可触的未来,发芽的智生7 小时前
触摸未来2025.10.10:记忆的种子,当神经网络拥有了临时工作区,小名喜忆记系统
人工智能·python·神经网络·机器学习·架构
mortimer7 小时前
在 Windows 上部署 NVIDIA Parakeet-TDT 遇到的坑
python·github·nvidia
Rock_yzh7 小时前
AI学习日记——卷积神经网络(CNN):完整实现与可视化分析
人工智能·python·深度学习·神经网络·学习·cnn
生信小白菜儿7 小时前
深度学习(DL)概念及实例操作
人工智能·python·深度学习
测试老哥8 小时前
如何编写好测试用例?
自动化测试·软件测试·python·功能测试·测试工具·职场和发展·测试用例
郝学胜-神的一滴9 小时前
Effective Python 第44条:用纯属性与修饰器取代旧式的 setter 与 getter 方法
开发语言·python·程序人生·软件工程
嫂子的姐夫10 小时前
11-py调用js
javascript·爬虫·python·网络爬虫·爬山算法
图亚Vanta10 小时前
Python入门第一课:Python安装、VSCode/Pycharm配置
vscode·python·pycharm