Wednesday, June 1, 2022
HomeWordPress Developmentfeatures - scraping web site knowledge to wordpress taxonomy

features – scraping web site knowledge to wordpress taxonomy


i wish to scrape knowledge from one other web site that does not present api to my wordpress website, and i need when i enter the information url ($baseTarget) it seems immediately within the taxonomy enter post_tags, title description, class, picture and many others in new publish. i do not know make it, i’ve searched however have not discovered any outcomes.

scrape.php

<?php

namespace AppServices;

use vokuhelperHtmlDomParser;

class MALService
{
    non-public $baseTarget="https://myanimelist.web";

    non-public operate init($path)
    {
        $curl = curl_init($this->baseTarget . $path);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Home windows; U; Home windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
        $html = curl_exec($curl);
        curl_close($curl);

        return HtmlDomParser::str_get_html($html);
    }

    public operate getCurrentAnimeSeason()
    {
        $html = $this->init('/anime/season');

        $wrapper = $html->findOne('#contentWrapper');
        $knowledge['seasonName'] = $wrapper->findOne('.season_nav > a')->innerText();

        // Get the present anime season sorts
        foreach ($wrapper->findMulti('.js-categories-seasonal > .seasonal-anime-list.js-seasonal-anime-list') as $index => $animeType) {
            $typeName = $animeType->findOne('.anime-header')->innerText();

            $knowledge['list'][$index] = [
                'typeName' => $typeName,
                'animes' => []
            ];

            // Get the anime record from every sorts
            foreach ($animeType->findMulti('.seasonal-anime.js-seasonal-anime') as $anime) {

                // Get the genres anime
                $genres = [];
                foreach ($anime->findMulti('.genres-inner > .style') as $style) {
                    $genreName = $genre->findOne('a')->innerText();
                    // Skip 18+ anime
                    if (strtolower($genreName) == 'hentai') proceed 2;
                    $genres[] = $genreName;
                }

                // Get picture anime
                $picture = $anime->findOne('.picture > a > img')->getAttribute('data-src');
                $picture = $picture != null ? $picture : $anime->findOne('.picture > a > img')->getAttribute('src');

                // Anime Information
                $knowledge['list'][$index]['animes'][] = [
                    'title' => $anime->findOne('.h2_anime_title > a')->innerText(),
                    'url' => $anime->findOne('.h2_anime_title > a')->getAttribute('href'),
                    'image' => $image,
                    'score' => strip_tags($anime->findOne('.score.score-label')->innerText()),
                    'member' => strip_tags($anime->findOne('.member.fl-r')->innerText()),
                    'producer' => $anime->findOne('.producer > a')->innerText(),
                    'eps' => $anime->findOne('.eps > a > span')->innerText(),
                    'source' => $anime->findOne('.source')->innerText(),
                    'genres' => $genres
                ];
            }
        }

        return $knowledge;
    }
}

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments