I want to use Petscan https://petscan.wmflabs.org/ to find articles that belong to certain categories, etc... It is easy to do this with the website they provide. I was wondering if there is a way to do this in Python. I create a URL to send the search query based on parameters given by the user, and it returns a list of Wikipedia article titles.
If you create a query it links to the URL sent, which contains all the parameters, above the table of results: Link to a pre-filled form for the query you just ran with and without auto-run. PSID is ....
Here's an example of how you can access a query programmatically and where the answers are found in the json returned:
import requests
import json
petscan = requests.get('https://petscan.wmflabs.org/?max_sitelink_count=&categories=cats&project=wikipedia&language=en&cb_labels_yes_l=1&edits%5Bflagged%5D=both&edits%5Bbots%5D=both&search_max_results=500&cb_labels_any_l=1&cb_labels_no_l=1&format=json&interface_language=en&edits%5Banons%5D=both&ns%5B0%5D=1&&doit=').json()
table = petscan['*'][0]['a']['*']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With