爬虫学习(三)用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)
相关推荐
西西学代码几秒前
A---(1)
学习
厦门小杨3 分钟前
数据驱动制造:智能铺布机如何成为服装工厂数字化的基石
学习·制造·服装厂·服装机械
DeanWinchester_mh16 分钟前
DeepSeek新论文火了:不用卷算力,一个数学约束让大模型更聪明
人工智能·学习
EmbedLinX24 分钟前
嵌入式之协议解析
linux·网络·c++·笔记·学习
楚轩努力变强26 分钟前
iOS 自动化环境配置指南 (Appium + WebDriverAgent)
javascript·学习·macos·ios·appium·自动化
盐焗西兰花29 分钟前
鸿蒙学习实战之路-Reader Kit自定义页面背景最佳实践
学习·华为·harmonyos
xhbaitxl35 分钟前
算法学习day38-动态规划
学习·算法·动态规划
Aliex_git36 分钟前
跨域请求笔记
前端·网络·笔记·学习
tritone36 分钟前
使用阿贝云免费云服务器学习Vagrant,是一次非常顺畅的体验。作为一名开发者
服务器·学习·vagrant
2501_9011478341 分钟前
面试必看:优势洗牌
笔记·学习·算法·面试·职场和发展