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)

读取:

相关推荐
吴佳浩2 小时前
大模型量化部署终极指南:让700亿参数的AI跑进你的显卡
人工智能·python·gpu
diegoXie3 小时前
Python / R 向量顺序分割与跨步分割
开发语言·python·r语言
程序员小白条3 小时前
0经验如何找实习?
java·开发语言·数据结构·数据库·链表
七牛云行业应用3 小时前
解决OSError: No space left... 给DeepSeek Agent装上无限云硬盘
python·架构设计·七牛云·deepseek·agent开发
liulilittle3 小时前
C++ 浮点数封装。
linux·服务器·开发语言·前端·网络·数据库·c++
BoBoZz193 小时前
CutWithScalars根据标量利用vtkContourFilter得到等值线
python·vtk·图形渲染·图形处理
失散134 小时前
Python——1 概述
开发语言·python
萧鼎4 小时前
Python 图像哈希库 imagehash——从原理到实践
开发语言·python·哈希算法
qq_251533594 小时前
使用 Python 提取 MAC 地址
网络·python·macos
小小8程序员4 小时前
STL 库(C++ Standard Template Library)全面介绍
java·开发语言·c++