当前位置:网站首页>正则爬取豆瓣Top250数据存储到CSV文件(6行代码)
正则爬取豆瓣Top250数据存储到CSV文件(6行代码)
2022-08-08 06:23:00 【PENG越】
利用正则爬取豆瓣TOP250电影信息
- 电影名字
- 电影年份
- 电影评分
- 评论人数

import requests
import csv
import re
# 不算导包的话正式代码6行 存储到csv文件
url = "https://movie.douban.com/top250?start={}&filter="
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36"}
obj = re.compile(r'a.*?<span class="title">(.*?)</span>.*?<br>\s+(.*?)&.*?:average">(.*?)</span>.*?<span>(.*?)人评价</span>', re.S)
with open('douban250.csv', 'w', encoding='utf-8', newline='') as file:
csv_write = csv.writer(file)
[csv_write.writerows(obj.findall(requests.get(url=url.format(page), headers=headers).text)) for page in range(0, 226, 25)]
利用正则拿截取部分数据还是挺好用的。此处使用的findall,如果部分数据做部分处理的话使用finditer会更合适。根据需求而言。
边栏推荐
- 八.Redis 主从复制
- MySQL数据库和数据表的增删改查基础
- 2. TF2 FAQ
- Chemical Materials Industry Report - Adipic Acid Market Status Research Analysis and Development Prospect Forecast
- Write carousel pictures with native js (and realize manual and automatic switching of pictures)
- 节流与防抖
- MySQL----存储引擎
- Detailed explanation of Scrapy crawler framework - comprehensive detailed explanation
- Consumer Goods Industry Report: Coconut Oil Market Status Research Analysis and Development Prospect Forecast
- 聊一聊数据库中的锁
猜你喜欢
随机推荐
2022届暑期实习笔经面经总结,已拿微软微信offer
四. Redis 事务、锁机制秒杀
Electronic payment market status quo of the study: 2022 volume is expected to increase to 314.1 billion yuan
Shell(一)
COSMIC: COmmonSense knowledge for eMotion Identification in Conversations
遥远的救世主
2.Explain详解与索引优化原则
Instant Noodle Industry Survey: Expected to Reach $43.6 Billion in 2028
MySQL索引事务
装机~ E5 剪辑
改变this指向
【熬夜整理近百份大厂面经】2022校招提前批面经总结分享(腾讯、字节、阿里、百度、京东等招聘信息+必考点+简历书写)
玫瑰精油市场研究:目前市场产值超过23亿元,市场需求缺口约10%
2. TF2 FAQ
Flutter学习开发资源整理与分享
demo:数组方法-商品查询
leetcode 5 最长回文子串std::pair 和 make_pair运用
一.Redis 概述
node模块
[BSidesCF 2020]Had a bad day1









