爬取猫咪交易网

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

代码展现:

具体代码:

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

相关推荐
太岁又沐风2 小时前
复现并修掉ART hook框架 Pine 调用原方法时的偶发 SIGSEGV
爬虫
黄忠5 小时前
01-系统架构设计-LangGraph状态机与多源异构RAG
python
zzzzzz3106 小时前
假如我是掘金管理员,我先给评论区装个'代码审查'系统
python·程序员·机器人
砍材农夫6 小时前
python环境|conda安装和使用(2)
后端·python
程序员龙叔19 小时前
编写高质量 Skill 系列 -- 如何设计需求分析与用例生成的 SKILL
自动化测试·软件测试·python·软件测试工程师·接口测试·性能测试·skill·ai测试
用户83562907805121 小时前
使用 Python 操作 Word 内容控件
后端·python
码云骑士1 天前
32-慢查询排查全流程(下)-索引优化实战与最左前缀原则
python
隔窗听雨眠1 天前
大模型加爬虫上篇:技术融合与架构革新
爬虫·架构
闵孚龙1 天前
《PyTorch 深度修炼》Dataset 和 DataLoader:数据如何喂给模型
人工智能·pytorch·python