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)

读取:

相关推荐
2501_916766545 分钟前
【Java】final关键字
java·开发语言
前端不太难14 分钟前
RN 列表里的「局部状态」和「全局状态」边界
开发语言·javascript·ecmascript
38242782730 分钟前
python3网络爬虫开发实战 第二版:绑定回调
开发语言·数据库·python
星月心城36 分钟前
面试八股文-JavaScript(第五天)
开发语言·javascript·ecmascript
dagouaofei40 分钟前
培训项目总结 PPT 工具对比评测,哪款更专业
python·powerpoint
wjs202440 分钟前
PostgreSQL 时间/日期处理指南
开发语言
Hello eveybody40 分钟前
用代码生成你的电影预告片(Python)
python
wniuniu_1 小时前
ceph心跳机制
开发语言·ceph·php
阿里嘎多学长1 小时前
2025-12-25 GitHub 热点项目精选
开发语言·程序员·github·代码托管
山沐与山1 小时前
【设计模式】 Python代理模式:从入门到实战
python·设计模式·代理模式