爬取猫咪交易网

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

代码展现:

具体代码:

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

相关推荐
wj3055853788 小时前
课程 9:模型测试记录与 Prompt 策略
linux·人工智能·python·comfyui
星寂樱易李8 小时前
iperf3 + Python-- 网络带宽、网速、网络稳定性
开发语言·网络·python
qingfeng154158 小时前
企业微信机器人开发:如何实现自动化与智能运营?
人工智能·python·机器人·自动化·企业微信
Python私教11 小时前
Playwright MCP 用 a11y 树抓页面:比全量 DOM 省 token 的采集 Agent
爬虫
彦为君11 小时前
Agent 安全:从权限提示到沙箱隔离
python·ai·ai编程
PILIPALAPENG12 小时前
Python 语法速成指南:前端开发者视角(JS 类比版)
前端·人工智能·python
用户83562907805113 小时前
Python 操作 PowerPoint 页眉与页脚指南
后端·python
枫叶林FYL13 小时前
项目九:异步高性能爬虫与数据采集中枢 —— 基于 Crawl<sub>4</sub>AI 与 Playwright 的现代化数据采集平台 项目总览
爬虫·python·深度学习·wpf
猫猫的小茶馆14 小时前
【Python】函数与模块化编程
linux·开发语言·arm开发·驱动开发·python·stm32