Scraping a wiki page for the “Periodic table” and all the links

后端 未结 3 1465
迷失自我
迷失自我 2020-12-25 08:55

I wish to scrape the following wiki article: http://en.wikipedia.org/wiki/Periodic_table

So that the output of my R code will be a table with the following columns:

3条回答
  •  渐次进展
    2020-12-25 09:46

    Do you have to scrape Wikipedia? You can run this SPARQL query against Wikidata instead (results):

    SELECT
      ?elementLabel
      ?symbol
      ?article
    WHERE
    {
      ?element wdt:P31 wd:Q11344;
               wdt:P1086 ?n;
               wdt:P246 ?symbol.
      OPTIONAL {
        ?article schema:about ?element;
                 schema:inLanguage "en";
                 schema:isPartOf .
      }
      FILTER (?n >= 1 && ?n <= 118).
      SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
    }
    ORDER BY ?n
    

    Sorry if this doesn't answer your question directly but this should help people looking to scrape the same information but in a clean manner.

提交回复
热议问题