Answer the question
In order to leave comments, you need to log in
Is PhpQuery acting weird?
I'm trying to parse the habr page habrahabr.ru/company/genue/blog/210610 using phpQuery.
The code is like this:
$url = 'http://habrahabr.ru/company/genue/blog/210610/';
$html = file_get_contents($url);
$doc = phpQuery::newDocument($html);
echo $doc;
Answer the question
In order to leave comments, you need to log in
In general, the issue is resolved.
Apparently phpQuery breaks off on a large number of home nodes, so I did this:
1.) Parse the head content from the enemy site
2.) In my case, add the desired tag to the head
3.) Cunning regular expression (stolen from foreign Internet) get the body content
4.) We glue and display
As a result, we have something like this
$url = 'http://habrahabr.ru/company/genue/blog/210610/';
$html = file_get_contents($url);
$doc = phpQuery::newDocumentHTML($html);
$doc['head']->prepend('<base href="'.$url.'" target="_blank"></base>');
preg_match("/<body[^>]*>(.*?)<\/body>/is", $html, $matches);
$new = '<html><head>'.$doc['head'].'</head><body>'.$matches[1].'</body></html>';
echo $new;
<?php
include 'phpQuery.php';
$url = 'http://habrahabr.ru/company/genue/blog/210610/';
$html = file_get_contents($url);
$doc = phpQuery::newDocument($html);
echo pq('html')->html();
check what file_get_contents returns, there may be a problem at this stage.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question