wikipedia php api plcontinue

37 views Asked by At

I am having such a hard time with the wikipedia API. I am trying to continue to the next batch of links using the continue url. here is my code. The problem is that the wikipedia API returns the exact same 500 links. It also returns links that are in fact on the webpage html but not displayed to the user, only seen in source code which of course is very frustrating. to make matters worse, i would love to use iwlinks so that i can get the url's but for some reason iwlinks doesnt work on that title. Can someone please help me with the continue. It seams there isnt much for php with this api out there. Thank you in advanced.

I wish there was a simple way to get the links relevant to the page theme and aside all others. as in if the page is a list of actors, return all links to the actors, and aside all non primary links. any way.

 public function __construct($constructor_params){
        $this->wiki_endpoint_url = 'https://en.wikipedia.org/w/api.php';
        $this->house_representatives_title = 'List of current members of the United States House of Representatives';
        $this->get_wiki_page_links_query_parameters = array("action" => "query",
                                                            "titles" => "dynamic",
                                                            "prop" => "links",
                                                            "pllimit" => "max",
                                                            "format" => "json"
                                                        );                              
      if($constructor_params['list'] = true && $constructor_params['genre'] = 'political'){
            $this->parse_wiki_list($this->house_representatives_title);
            $this->parse_wiki_political_link_list();
        }
    }





private function parse_wiki_list($wiki_page_title){
        $this->get_wiki_page_links_query_parameters['titles'] = $wiki_page_title;
        $built_url = $this->wiki_endpoint_url . '?' . http_build_query($this->get_wiki_page_links_query_parameters);
        echo $built_url;
        $wiki_json = $this->curl_fetch_return($built_url);
        $this->wiki_json_decoded = json_decode($wiki_json, true);
        // var_dump($this->wiki_json_decoded);
        if(!empty($this->wiki_json_decoded) && !empty($this->wiki_json_decoded['continue']) && !empty($this->wiki_json_decoded['continue']['plcontinue']) && !empty($this->wiki_json_decoded['continue']['continue'])){
            $this->get_wiki_page_links_query_parameters['plcontinue'] = $this->wiki_json_decoded['continue']['plcontinue'];
            $this->get_wiki_page_links_query_parameters['formatversion'] = 2;
            $built_url = $this->wiki_endpoint_url . '?' . http_build_query($this->get_wiki_page_links_query_parameters); 
            echo '<br>';
            echo $built_url;
            echo '<br>';
            $wiki_json = $this->curl_fetch_return($built_url);
            array_merge($this->wiki_json_decoded,json_decode($wiki_json, true));
        }
}

its been hard navigating their documentation.

0

There are 0 answers