r/learnpython • u/IllustratorUnfair330 • 1h ago
How would you approach scraping from Wikipedia using Python?
Hey everyone,
I'm learning Python web scraping and wanted to see how more experienced programmers would approach this task. the task is to scrape all Wikipedia articles of Academy Award winners listed under Wikipedia. Source: https://en.wikipedia.org/wiki/List_of_Academy_Award–winning_films
I'm specifically interested in collecting every film listed on that Wikipedia page and downloading its individual Wikipedia article.
I'd really appreciate seeing how others would implement this from scratch using Python, preferably with requests and BeautifulSoup.
A few things I'm curious about:
- How would you extract all the film links without missing any?
- How would you download and save each film's Wikipedia article?
- How would you handle errors or failed downloads?
- How would you verify that all articles were successfully collected?
If possible, I'd love to see a complete working Python example rather than just a general explanation. I'm trying to compare different approaches and understand what a reliable solution would look like.
Thanks in advance!
12
u/ivovis 1h ago
A while ago I downloaded the whole of Wikipedia to a usb drive using Kiwix, suspect this would be the best way without hammering actual Wikipeadia
•
u/roywill2 57m ago
Bots and scrapers and robots are killing a lot of websites. The least you can do is give money to wikipedia in compensation.
•
u/SpiritedInflation835 52m ago
Wikipedia has an API to access the articles' contents, without having to visit all the websites.
4
u/odaiwai 1h ago
It's python so a lot of these problems are already solved. Start here: https://pypi.org/project/wikipedia/ and see if it matches your needs. It has links to a few more advanced projects.
•
u/ivosaurus 35m ago
We doin' your homework for you now?
•
u/aiuniverse-3p3_here 47m ago
bro i did same for my project here is simple way use requests + beautifulsoup dont uses selenium for wikipedia its slow
first get the main page find all <a> tags with /wiki/ in it for each links use requests get and save it use try-except, if one fails, skip it and save its name in a failed list at end check len of saved files vs len of links you will know if you missed any
small code: import requests from bs4 import BeautifulSoup url = "https://en.wikipedia.org/wiki/List_of_Academy_Award-winning_films" soup = BeautifulSoup(requests.get(url).text, "html.parser") links = [a['href'] for a in soup.find_all('a', href=True) if '/wiki/' in a['href']]
try this it works
•
u/esaule 7m ago
Don't! There is much easier
You can hit the wikidata SPARQL endpoint and make a query against the database and get the data that comes back to your formatted.
Much easier to do and maintain!
0
u/mkhanwrites_ 1h ago
You will probably need some kind of for loop in your code - specifically you'll be using a basic searching algorithm like Breadth-First Search or Depth-First Search. You could also technically implement this recursively. I don't think I'll provide a code sample, sorry about that.