DUPLICATE MODS, PLEASE DELETE, SORRY!

Joined
Sep 4, 2023
Messages
5
Reaction score
0
I'm not massively au fait with the world of coding and scripting, so sorry if this seems like a daft question!

What I'd like to do is to pull up a number of web pages in sequence (for example: https://www.karaoke-version.co.uk/suggestion_10.html – I'd want to load suggestion_9, suggestion_10, suggestion_11 etc.) and search for a string of text in each page.

The last time I did any sort of coding was BASIC, where I'd probably use a FOR / NEXT loop – that was a long time ago though. If anyone could give me pointers on how to do this it would be very welcome!
 
Joined
Jul 4, 2023
Messages
474
Reaction score
58
For this case I suggest use python with package called "requests" to fetch web pages and package "beautifulsoup4" for parsing the HTML content, e.g.
Python:
import requests
from bs4 import BeautifulSoup

# Define the URL pattern and search string
base_url = "https://www.karaoke-version.co.uk/suggestion_{}.html"
search_string = "Dirty Love"

# Define the range of pages to scrape
start_page = 9
end_page = 11  # Change this to the last page you want to scrape

# Loop through the pages
for page_num in range(start_page, end_page + 1):
    url = base_url.format(page_num)
    print("\n", url, sep="")

    # Send an HTTP GET request to the URL
    response = requests.get(url)

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

        # Search for the desired string in the HTML
        print(f"String: {search_string}")
        if not search_string in soup.get_text():
            print("not ", end="")
        print(f"found on page {page_num}")
    else:
        print(f"Failed to retrieve page")
 
Last edited:

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top