import requests from bs4 import BeautifulSoup

def crawl_novel(url): # Send an HTTP GET request to the novel's main page response = requests.get(url)

# Check if the request was successful
if response.status_code == 200:
    # Parse the novel's main page content
    soup = BeautifulSoup(response.content, "html.parser")

    # Find all the chapter links
    chapter_lists = soup.find_all("div", class_="flex flex-between book-info-main")

    # Loop through each chapter link and extract chapter content
    for chapter_list in chapter_lists:
        for chapter in chapter_list.find_all("a", rel="chapter"):
            chapter_title = chapter.text  # Get chapter title
            chapter_url = "https://www.biquge66.net" + chapter["href"]  # Build complete chapter URL

            # Send an HTTP GET request to get the first page of the chapter content
            chapter_response = requests.get(chapter_url)
            chapter_soup = BeautifulSoup(chapter_response.content, "html.parser")

            # Find the first page of chapter content
            chapter_content = chapter_soup.find("div", id="booktxt")

            # Extract and print the first page of chapter content
            if chapter_content:
                chapter_text = chapter_content.text.replace("本站最新网址:www.biquge66.net", "")  # Remove site info

                # Check if there is a second page
                chapter_url2 = chapter_url.replace(".html", "_2.html")
                chapter_response2 = requests.get(chapter_url2)
                chapter_soup2 = BeautifulSoup(chapter_response2.content, "html.parser")
                chapter_content2 = chapter_soup2.find("div", id="booktxt")

                # If there is a second page, concatenate it with the first page
                if chapter_content2:
                    chapter_text2 = chapter_content2.text.replace("本站最新网址:www.biquge66.net", "")  # Remove site info
                    chapter_text += chapter_text2

                print(f"{chapter_title}:\n{chapter_text}\n")
            else:
                print(f"Unable to retrieve chapter content: {chapter_title}\n")
else:
    print(f"Failed to retrieve novel page: {url}")

def search_novel(): novel_name = input("Enter the novel name: ")

# Construct the search URL
search_url = f"https://www.biquge66.net/search/?searchkey={novel_name}"

# Send an HTTP GET request to the search page
search_response = requests.get(search_url)

# Check if the request was successful
if search_response.status_code == 200:
    # Parse the search page content
    search_soup = BeautifulSoup(search_response.content, "html.parser")

    # Find the first search result and extract its href
    first_result = search_soup.find("div", class_="image").find("a")
    if first_result:
        novel_href = first_result["href"]

        # Construct the URL for the novel's main page
        novel_url = f"https://www.biquge66.net{novel_href}"

        crawl_novel(novel_url)
    else:
        print("No search results found for the given novel name.")
else:
    print(f"Failed to retrieve search results page: {search_url}")

Ask the user to choose a novel source

novel_source = input("Choose a novel source (1 or 2): ")

if novel_source == "1": crawl_novel("https://www.biquge66.net/book/4772/") elif novel_source == "2": search_novel() else: print("Invalid novel source chosen. Please try again."

import tkinter as tkfrom tkinter import ttkfrom tkinter import messageboxfrom seleniumwebdriverchromeoptions import Optionsfrom selenium import webdriverfrom seleniumwebdrivercommonkeys import Keysimp

原文地址: https://www.cveoy.top/t/topic/iV62 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录