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)

读取:

相关推荐
闲猫1 分钟前
LangGraph / Capabilities / Stores
python·agent·langgraph
QH139292318804 分钟前
NVIDIA H200 H300服务器
运维·服务器·开发语言·网络·信息与通信
pjj1985412 分钟前
机器学习-NumPy2
人工智能·python·机器学习
tang7778922 分钟前
Scrapy框架动态IP自动轮换集成配置教程
爬虫·tcp/ip·scrapy·架构·爬虫代理·动态ip
OPEN-F24 分钟前
Python进阶教程:单元测试与代码质量
开发语言·python·单元测试
阿里嘎多学长25 分钟前
2026-08-20 GitHub 热点项目精选
开发语言·程序员·github·代码托管
其实防守也摸鱼34 分钟前
Codex破局:前端组件秒级生成的技术文章大纲
开发语言·前端·人工智能·学习·安全·web安全
Logintern091 小时前
装饰器和洋葱模式的区分
开发语言·python·架构
冻柠檬飞冰走茶1 小时前
《数据结构实验指导-C++语言版》 在顺序表 list 中查找元素 x
开发语言·数据结构·c++·算法·list
Brilliantwxx1 小时前
【C++】 高阶数据结构图(1)并查集
开发语言·数据结构·c++