• You MUST read the Babiato Rules before making your first post otherwise you may get permanent warning points or a permanent Ban.

    Our resources on Babiato Forum are CLEAN and SAFE. So you can use them for development and testing purposes. If your are on Windows and have an antivirus that alerts you about a possible infection: Know it's a false positive because all scripts are double checked by our experts. We advise you to add Babiato to trusted sites/sources or disable your antivirus momentarily while downloading a resource. "Enjoy your presence on Babiato"

how to scraping website data to wordpress metabox?

saranganime

Member
Dec 23, 2019
34
8
8
i want to scrape data from another website that doesn't provide api to my wordpress site, and i want when input the data url ($baseTarget) it appears directly in the metabox post_tags, title description, category, image etc in new post. i don't know how to make it, i have searched but haven't found any results.

PHP:
<?php

namespace App\Services;

use voku\helper\HtmlDomParser;

class MALService
{
    private $baseTarget = 'https://myanimelist.net';

    private function init($path)
    {
        $curl = curl_init($this->baseTarget . $path);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; 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 function getCurrentAnimeSeason()
    {
        $html = $this->init('/anime/season');

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

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

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

            // Get the anime list from each types
            foreach ($animeType->findMulti('.seasonal-anime.js-seasonal-anime') as $anime) {

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

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

                // Anime Data
                $data['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 $data;
    }
}
 
I have tried it but it's not efficient, it's like I made a post as usual. I want when the url is added to the metabox it appears immediately.

Screenshot_1.png

When you say "meta box" do you mean a post meta box thats draggable? maybe this could be achieved with custom post types?
 
AdBlock Detected

We get it, advertisements are annoying!

However in order to keep our huge array of resources free of charge we need to generate income from ads so to use the site you will need to turn off your adblocker.

If you'd like to have an ad free experience you can become a Babiato Lover by donating as little as $5 per month. Click on the Donate menu tab for more info.

I've Disabled AdBlock