爬取猫咪交易网

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

代码展现:

具体代码:

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

相关推荐
Csvn14 小时前
🌟 LangChain 30 天保姆级教程 · Day 13|OutputParser 进阶!让 AI 输出自动转为结构化对象,并支持自动重试!
python·langchain
cch891814 小时前
Python主流框架全解析
开发语言·python
sg_knight15 小时前
设计模式实战:状态模式(State)
python·ui·设计模式·状态模式·state
好运的阿财15 小时前
process 工具与子agent管理机制详解
网络·人工智能·python·程序人生·ai编程
张張40815 小时前
(域格)环境搭建和编译
c语言·开发语言·python·ai
weixin_4235339915 小时前
【Windows11离线安装anaconda、python、vscode】
开发语言·vscode·python
Ricky111zzz15 小时前
leetcode学python记录1
python·算法·leetcode·职场和发展
小白学大数据16 小时前
Selenium+Python 爬虫:动态加载头条问答爬取
爬虫·python·selenium
Hui Baby16 小时前
springboot读取配置文件
后端·python·flask
阿Y加油吧16 小时前
回溯法经典难题:N 皇后问题 深度解析 + 二分查找入门(搜索插入位置)
开发语言·python