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)

读取:

相关推荐
用户019027581612 分钟前
如何用 Python 计算 DMA 平行线差指标?
python
轻舟技术A4 分钟前
Pi 的 Rust 实现来了:rpi,不止一个终端 Agent
开发语言·后端·rust
额额额对了22 分钟前
嵌入式 Linux 启动程序文件
开发语言·嵌入式硬件·php
子非鱼a26 分钟前
【WEB】EasySSTI
java·开发语言·前端
奈葵32 分钟前
Python
开发语言·python
happylifetree39 分钟前
Python54-55:核心语法-数据容器-字典dict-案例
python
小小张说故事40 分钟前
Python 迭代器和生成器到底啥区别?3 个例子讲透,别再背概念了
python
Nebula_g1 小时前
JavaSE项目实践:红包雨-线程池/线程
java·开发语言
外收内放1 小时前
Python基础语法练习题(56优化版补充)
开发语言·python