爬虫学习(三)用beautiful 解析html


安装库



py 复制代码
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/119.0.0.0 Safari/537.36 Edg/119.0.0.0"

}
for start_num in range(0,250,25):

    response = requests.get(f"https://movie.douban.com/top250?start={start_num}",headers = headers)
    html = response.text
    soup = BeautifulSoup(html,"html.parser")
    all_title = soup.findAll("span",attrs={"class":"title"})
    for title in all_title:
        title_string = title.string
        if "/" not in title_string:
            print(title_string)
相关推荐
LccKyI39 分钟前
C#学习day06(方法/函数及其关键字,附思维导图)
经验分享·学习·c#
xian_wwq1 小时前
【学习笔记】Loop Engineering,从手动提示到目标驱动自动化-13/16
笔记·学习·自动化
殷忆枫1 小时前
K210 BOX学习笔记:环境搭建及模型训练部署
学习
qq_185198692 小时前
SpingBoot3入门学习-Web开发-三
java·数据库·学习
lifallen2 小时前
Avernet:Agent 的组织网络
人工智能·学习·ai·开源软件·ai编程
我爱cope2 小时前
【计算机网络 | 数据链路层2:差错检测与纠正:奇偶校验、校验和、CRC 分别怎么工作?】
网络·学习·计算机网络
知识分享小能手3 小时前
线性代数学习教程,从入门到精通,矩阵及其运算 — 完整知识点与详细推导(3)
学习·线性代数·矩阵
小弥儿3 小时前
Firecrawl:把整个网页变成 AI 可查询的数据库
数据库·人工智能·学习
woshihuanglaoshi3 小时前
鸿蒙老旧项目升级改造高级:API废弃迁移/ArkTS语法升级/架构重构策略/增量迁移/风险管控方案
学习·华为·重构·架构·harmonyos·鸿蒙
zhangrelay3 小时前
ROS 2 Lyrical 第2章 ROS 2系统架构与核心概念
linux·笔记·学习·ubuntu·ros2