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)

读取:

相关推荐
闲猫9 小时前
LangChain / Core components / Models
开发语言·python·langchain
-银雾鸢尾-10 小时前
C#中的索引器
开发语言·c#
Qlittleboy11 小时前
PHP的接口参数传递的过多,max_input_vars = 5000
开发语言·php
Aurorar0rua11 小时前
CS50 x 2024 Notes Algorithms - 02
c语言·开发语言·学习方法
en.en..11 小时前
冒泡排序与选择排序完整对比解析
开发语言·数据结构·算法·c#·排序算法
兰令水11 小时前
hot100【acm版】【2026.7.18打卡-java版本】
java·开发语言·算法
cui_ruicheng11 小时前
Python从入门到实战(十三):模块、包与环境管理
开发语言·python
就叫飞六吧12 小时前
子页面和dialog案例
开发语言·javascript·ecmascript
geovindu12 小时前
CSharp: Decorator Pattern
开发语言·后端·c#·装饰器模式·结构型模式
李宸净12 小时前
Web自动化测试selenium+python
前端·python·selenium