Tutorial: How to parse HTML Code in PHP

It is very hard to find the right selectors to parse html code in php.

Now i have found the ultimate solution!

Tutorial: How to parse HTML Code in PHP
Parse HTML Code in PHP
$fake_user_agent = "Mozilla/5.0 (X11; Linux i686) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.47 Safari/536.11";
ini_set('user_agent', $fake_user_agent);

libxml_use_internal_errors(true);
$dom = new DomDocument;
$dom->loadHTMLFile("https://socialblade.com/youtube/channel/UCJETl_inEdp0XXXXXXXXXQ");
$xpath = new DomXPath($dom);
$nodes = $xpath->query("//*[@id=\"YouTubeUserTopInfoBlock\"]/div[3]/span[2] | //*[@id=\"YouTubeUserTopInfoBlock\"]/div[4]/span[2]");
header("Content-type: text/plain");
foreach ($nodes as $i => $node) {
    echo "Node($i): ", $node->nodeValue, "\n";
} 

With this code you are able to fake the user agent and bypass the socialblade filter. You can also easily change the xpath code to parse the html code in php.

Safari -> Inspect Element -> Right Click -> Copy -> Copy xpath

And youre done! Its such easy. Just change the URL and xpath code and everything works fine.

I spent so much hours on finding the right selectors and the correct paths to the data i want and now it is just working within 30 seconds.

Bildschirmfoto-2019-10-31-um-16.01.58

Bewerte diesen Artikel

0 Bewertung(en), Durchschnitt: 0 von 5

Dieser Artikel wurde noch nicht bewertet.

Es tut uns leid, dass dir der Beitrag nicht gefallen hat.

Lass uns genau diesen Artikel überarbeiten.

Erzähle uns, was wir besser machen können.

Beitrag teilen

Hinterlasse einen Kommentar

  Abonnieren  
Benachrichtige mich bei
Scroll to Top