Is there a way to extract all links from only the "See Also" section in a Wikipedia article through Wikpedia API?
I wondering a method but I'm not able to find one.
Is there a way to extract all links from only the "See Also" section in a Wikipedia article through Wikpedia API?
I wondering a method but I'm not able to find one.
Yes, you can do it by using Wikipedia API with action=parse. For this goal we need two properties: sections
and links
. For example for Wikipedia article Chicago we use the next query to get the index of the section with name "See also":
https://en.wikipedia.org/w/api.php?action=parse&prop=sections&page=Chicago
From response we see that it is 43. Then we use that index to get the links only in this section:
https://en.wikipedia.org/w/api.php?action=parse&prop=links&page=Chicago§ion=43
Note: The last response can include also links which come from some templates, as in our case Portal:Chicago and Portal:Illinois. If you want you can filter them by using namespace &ns=0 in your request.
Not directly though the API. MediaWiki tracks links on a per-page basis, it doesn't store information about which section the link comes from.
I think your best option is to get the HTML of the section, parse it and collect all <a href
elements.