r/learnpython • • 6d ago
How would you approach scraping from Wikipedia using Python?
[deleted] — view deleted post
5
Upvotes
r/learnpython • • 6d ago
[deleted] — view deleted post
40
u/ivovis 6d 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
24
u/ivosaurus 6d ago
We doin' your homework for you now?
26
u/SpiritedInflation835 6d ago
Wikipedia has an API to access the articles' contents, without having to visit all the websites.
11
u/odaiwai 6d 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.
16
u/desrtfx but other languages pro 6d ago
If your first instinct is to scrape you're doing it wrong.
First is always to check if there is an API and if so, use it.
Scraping is always the very last resort if there are absolutely no other options.
7
u/esaule 6d 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!
21
u/roywill2 6d ago
Bots and scrapers and robots are killing a lot of websites. The least you can do is give money to wikipedia in compensation.
3
u/Pirate_OOS 6d ago
Wikipedia has implemented a blocker. It stopped my script to scrape movie plots using BeautifulSoup from working.
3
u/szayl 6d ago
I wouldn't scrape it. I would just download the entire Wikipedia.
1
u/dariusbiggs 6d ago
Clone Wikipedia from its data source (there is probably something for it), then develop and learn against a locally hosted container.
1
u/Umustbecrazy 6d ago
That's the exact project the Book Webscraping in/with Python uses as it's starting tutorial.
1
u/longgamma 5d ago
Just download the offline version.
1
u/GreenWoodDragon 5d ago
Check if there's an API first. Don't just dive in and scrape the html.
0
u/mkhanwrites_ 6d 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.
-3
u/vilette 6d ago
That's a thing to code with ai