爬虫学习(三)用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)
相关推荐
zilikew21 分钟前
Flutter框架跨平台鸿蒙开发——桌面宠物APP的开发流程
学习·flutter·harmonyos·鸿蒙·宠物
Sarvartha2 小时前
LangChain 入门核心知识学习笔记
笔记·学习·langchain
QZ_orz_freedom2 小时前
后端学习笔记-苍穹外卖
笔记·学习
沉默-_-6 小时前
力扣hot100-子串(C++)
c++·学习·算法·leetcode·子串
●VON6 小时前
从系统亮度监听到 UI 重绘:Flutter for OpenHarmony TodoList 深色模式的端到端响应式实现
学习·flutter·ui·openharmony·布局·von
新-code6 小时前
ros学习
学习·机器人
yi.Ist7 小时前
关于若干基础的几何问题
c++·学习·算法·计算几何
曦月逸霜7 小时前
深入理解计算机系统——学习笔记(持续更新~)
笔记·学习·计算机系统
我的xiaodoujiao7 小时前
使用 Python 语言 从 0 到 1 搭建完整 Web UI自动化测试学习系列 43--添加allure测试报告显示信息和其他封装方法
python·学习·测试工具·allure
curry____3038 小时前
数据结构学习笔记
数据结构·笔记·学习