How does phpquery work? Trying to get the value of the <title> tag

I am new to phpQuery . I need to perform the simple task of retrieving the contents of an HTML TITLE tag on a web page. In this case, I am trying to get the title of the content "Yahoo!", it should be "Yahoo!"

I do this with phpQuery, but now it works

// Testing phpQuery $result = phpQuery::newDocumentFile($scraps['Scrap_yahoo']->getPage('http://www.yahoo.com','','off')) ->find('title'); echo $result->text(); 

Can someone let me know how to do this?

Best wishes,

+4
source share
1 answer

I think the problem might be calling phpQuery with ::newDocumentFile() . This function needs a file name (not sure if the URL works), but I suspect your ->getPage() already typing the file already. If so, use regular ::newDocument() like this:

 $html = file_get_contents("http://www.yahoo.com/"); $pq = phpQuery::newDocument($html); print $pq->find("title")->text(); 

It works for me.

+6
source

Source: https://habr.com/ru/post/1334234/


All Articles