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)

读取:

相关推荐
紫金修道6 小时前
【DeepAgent】概述
开发语言·数据库·python
Via_Neo6 小时前
JAVA中以2为底的对数表示方式
java·开发语言
书到用时方恨少!6 小时前
Python multiprocessing 使用指南:突破 GIL 束缚的并行计算利器
开发语言·python·并行·多进程
cch89186 小时前
PHP五大后台框架横向对比
开发语言·php
Warson_L7 小时前
Python 常用内置标准库
python
天真萌泪7 小时前
JS逆向自用
开发语言·javascript·ecmascript
Warson_L7 小时前
Python 函数的艺术 (Functions)
python
Warson_L7 小时前
Python 流程控制与逻辑
后端·python
野生技术架构师7 小时前
一线大厂Java面试八股文全栈通关手册(含源码级详解)
java·开发语言·面试
long_songs7 小时前
手柄键盘映射器【github链接见文末 】
python·游戏·计算机外设·pygame·软件推荐·手柄映射键盘