簡體   English   中英

如何使用 BeautifulSoup 抓取下一頁?

[英]How can I scrape the next page using BeautifulSoup?

我想在這個網站上閱讀漫畫時刮下下一章:
https://www.mangaworld.io/ ,這不是一個簡單的鏈接,所以我不能使用計數器,它就像 1, 2, 3... 9, a, b, c, d。 我試過用計數器但沒有結果。

您可以使用此示例如何對請求進行分頁:

import requests
from bs4 import BeautifulSoup


url = "https://www.mangaworld.io"

params = {"page": 1}

for page in range(1, 4):  # <--- increase the page number here
    print("Page {}...".format(page))
    print("-" * 80)
    params["page"] = page
    soup = BeautifulSoup(
        requests.get(url, params=params).content, "html.parser"
    )

    for a in soup.select(".comics-grid a.manga-title"):
        print(a.get_text(strip=True))

印刷:

Page 1...
--------------------------------------------------------------------------------
Isekai Kenkokuki
Taming My Boss
Omukae Shibuya-kun
Touch to Unlock
Amagami-san Chi no Enmusubi
Clover
Kirei ni shite moraemasu ka
DanMachi: Sword Oratoria
Kishuku Gakkou no Juliet
Kaiju No. 8
Four Knights of the Apocalypse
Creepy Cat
Little Witch Academia
Blue Box
SHY
Okaeri Alice
Page 2...
--------------------------------------------------------------------------------
Tokyo卍Revengers
Kamonohashi Ron no Kindan Suiri
Stairway of Time
Koi ka Mahou ka Wakaranai!
One Piece
JoJo's Bizarre Adventure Part 8 - JoJolion
Silent War
Sweet Spooky Darling
Martial Peak
Tale of a Scribe Who Retires to the Countryside
Oshi no Ko
Goblin Slayer
Fairy Tail: 100 Years Quest
Boku no Hero Academia
Evil Heroes
Ao no Exorcist
Page 3...
--------------------------------------------------------------------------------
Positively Yours
Fire Brigade of Flames
Whispering You a Love Song
Kiss x Sis
Zense Coupling
Gallery L
The Bloody Merchant Empress and the Cold Husband's Forceful Doting
Isekai Maou to Shoukan Shoujo Dorei Majutsu
Time Lover
Lunar Lover
Kanojo mo Kanojo
Himekishi ga Classmate!
Leveling Up, by Only Eating!
Dr. Stone
Murim Login
Candy Flurry

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM