爬虫学习(三)用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)
相关推荐
春风解人意25 分钟前
从零开始学习嵌入式P32----网络基础之TCP
c语言·网络·学习·tcp/ip
传奇开心果编程2 小时前
【Rust入门知识点学与练】第21课:Trait 进阶 Advanced Traits
开发语言·学习·rust
水巷石子2 小时前
备考系统架构设计师第一天
学习·架构·软考·设计·考试
是隼人3 小时前
buuctf-pwn inndy_echo(32位fmt)题解(学习过程持续更新)
c语言·学习·安全·pwn入门·ctf入门
xian_wwq4 小时前
【学习笔记】深度认知系列-第16讲-提示词工程
人工智能·笔记·学习
洛阳纸贵4 小时前
MATLAB-matlab基础知识
学习·算法·matlab
Vcaker4 小时前
Linux学习25-harbor私有仓库部署
linux·运维·学习
留白_4 小时前
【tableau入门学习】5、筛选器、参考线和集
学习·tableau
youm20035 小时前
认识Redis
redis·笔记·学习
亮工硬件5 小时前
1-11 STM32内部FLASH(数据掉电保存)
笔记·stm32·单片机·嵌入式硬件·学习