python爬虫获取豆瓣前top250的标题(简单)

今天是简略的一篇,简单小实验

python 复制代码
import requests
from bs4 import BeautifulSoup

# 模拟浏览器的构成(请求头)
headers = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36 Edg/123.0.0.0"
}

for start_num in range(0,250,25):
    # 获取豆瓣top榜上前250部电影的响应内容
    response = requests.get(f"https://movie.douban.com/top250?start={start_num}", headers=headers)
    html = response.text
    # 传入方法,指定解析器为html.parser"
    soup = BeautifulSoup(html, "html.parser")
    all_titles=soup.findAll("span",attrs={"class":"title"})
    for title in all_titles:
        title_string=title.string
        if "/" not in title_string:
            print(title_string)

读取:

相关推荐
深蓝电商API几秒前
爬虫自动化测试:Pytest + Allure 漂亮报告生成
爬虫
2401_8414956414 分钟前
【LeetCode刷题】跳跃游戏
数据结构·python·算法·leetcode·游戏·贪心算法·数组
BoBoZz1931 分钟前
MarchingCases marchingcubes算法15种情况的展示
python·vtk·图形渲染·图形处理
彼岸花开了吗41 分钟前
构建AI智能体:五十二、反应式智能体:基于“感知-行动”,AI世界的条件反射
人工智能·python·agent
沐知全栈开发44 分钟前
C 标准库 - <locale.h>
开发语言
老毛肚1 小时前
Java两种代理模式详解
java·开发语言·代理模式
小此方1 小时前
Re:从零开始学C++(二)基础精讲·中篇:引用
开发语言·c++·底层
weixin_429690721 小时前
# 数字人系统开发:如何选择可靠的开源方案在人工智能和虚
人工智能·python·开源
艾上编程1 小时前
《Python实战小课:数据分析场景——解锁数据洞察之力》导读
python·数据挖掘·数据分析
Lyinj1 小时前
从一个编辑校验问题谈接口设计的边界
java·spring boot·python·学习