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)

读取:

相关推荐
颜*鸣&空5 小时前
QT程序实现串口通信案例
开发语言·qt
烤汉堡5 小时前
Python入门到实战:post请求+cookie+代理
爬虫·python
无限进步_5 小时前
C语言动态内存的二维抽象:用malloc实现灵活的多维数组
c语言·开发语言·数据结构·git·算法·github·visual studio
luod5 小时前
Python异常链
python
e***19355 小时前
爬虫学习 01 Web Scraper的使用
前端·爬虫·学习
froginwe115 小时前
Maven 仓库概述
开发语言
我不是QI6 小时前
周志华《机器学习---西瓜书》 一
人工智能·python·机器学习·ai
今天没ID6 小时前
Python 编程实战:从基础语法到算法实现 (1)
python
二川bro6 小时前
Python在AI领域应用全景:2025趋势与案例
开发语言·人工智能·python