爬取蝉妈妈数据平台商品数据

本文旨在交流学习,勿作他用,否则后果自负
环境 linux+pycharm+anaconda

import json
import csv
import requests
from usere_agent import UA
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)


headers = {
   
 'Accept': '*/*',
 'Accept-Encoding': 'gzip, deflate, br',
 'Accept-Language': 'zh-CN,zh;q=0.9',
 'Connection': 'keep-alive',
 'Content-Length': '238',
 'Content-Type': 'application/x-www-form-urlencoded',
 'Host': 'api-service.chanmama.com',
 'Origin': 'https://www.chanmama.com',
 'Referer': 'https://www.chanmama.com/promotionRank',
 'User-Agent': UA
}

cl_url=["女装","男装",
  • 5
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
爬取妈妈视频数据可以使用Python中的Web爬虫技术,以下是爬取妈妈视频数据的步骤: 1. 导入所需的第三方库,如requests和BeautifulSoup。 2. 使用requests库发送HTTP请求,获取妈妈视频主页的HTML源码。 3. 使用BeautifulSoup库解析HTML源码,提取视频的相关信息,如视频标题、时长、播放量等。 4. 进入视频详情页,获取视频的详细信息,如视频的URL、发布时间、描述等。 5. 将爬取到的数据保存到本地文件或数据库中,以便后续处理和分析。 以下是一个简单的示例代码: ```python import requests from bs4 import BeautifulSoup url = "http://www.chanmama.com/video/" # 发送HTTP请求,获取HTML源码 response = requests.get(url) html = response.text # 使用BeautifulSoup解析HTML源码 soup = BeautifulSoup(html, "html.parser") # 提取视频信息 videos = [] video_elements = soup.find_all("div", class_="video-box") for element in video_elements: video = {} video["标题"] = element.find("a", class_="video-title").text video["时长"] = element.find("span", class_="video-time").text video["播放量"] = element.find("span", class_="video-views").text videos.append(video) # 进入视频详情页,获取详细信息 for video in videos: video_url = "http://www.chanmama.com" + video["标题"]["href"] response = requests.get(video_url) video_html = response.text soup = BeautifulSoup(video_html, "html.parser") video["链接"] = soup.find("video")["src"] video["发布时间"] = soup.find("span", class_="video-publish-time").text video["描述"] = soup.find("div", class_="video-description").text # 保存数据到本地文件或数据库 # ... ``` 以上代码仅是一个基本示例,实际的爬取过程中可能需要处理更多的特殊情况,如网页反爬机制、分页加载等。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值