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)

读取:

相关推荐
北冥有羽Victoria3 分钟前
TGC:深度时序图聚类的动态建模与时空平衡|ICLR 2024 深度解读
人工智能·python·算法·机器学习·支持向量机·聚类
Ssan PRIN5 分钟前
Modbus报文详解
服务器·开发语言·php
ZC跨境爬虫7 分钟前
Playwright核心操作实战精讲(QQ空间+百度+iframe,含等待_键盘_iframe操作)
前端·爬虫·python·计算机外设
枫叶丹47 分钟前
【HarmonyOS 6.0】ArkUI Swiper 组件:深入掌握滑动状态变化事件回调
开发语言·华为·harmonyos
小陈工10 分钟前
2026年4月4日技术资讯洞察:异步编程范式重塑、架构理性回归与开发者体验革命
开发语言·人工智能·python·机器学习·架构·数据挖掘·回归
CAE虚拟与现实13 分钟前
Python在Windows 平台上引入了一种新的安装与运行时管理机制
开发语言·python
ZC跨境爬虫15 分钟前
对称加密算法详解(DES篇):特点、实现与逆向实操
前端·javascript·爬虫
财经资讯数据_灵砚智能16 分钟前
基于全球经济类多源新闻的NLP情感分析与数据可视化(日间)2026年4月4日
大数据·人工智能·python·信息可视化·自然语言处理·ai编程
数据知道18 分钟前
Claude Code 进行“从头重写”的项目 Claw Code全面介绍(claw-code)
python·ai·claude code
ZHENGZJM25 分钟前
用大语言模型(LLM)自动化扩充 OJ 系统测试数据:Python 脚本实战
python·语言模型·自动化