PhpQuery如何工作?尝试获取< title>的值;标签 [英] How does PhpQuery work? Trying to get the value of <title> tag

查看:244
本文介绍了PhpQuery如何工作?尝试获取< title>的值;标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 phpQuery 的新手.我需要完成一个简单的任务,即获取网页的HTML TITLE标记的内容.在这种情况下,我尝试获取"Yahoo!"的标题内容应该是"Yahoo!".

I'm new to phpQuery. I need to achieve the simple task of getting the content of the HTML TITLE tag of a webpage. In this case I'm trying to get the title content of "Yahoo!" that should be "Yahoo!".

我正在使用phpQuery进行此操作,但现在可以正常使用

I'm doing this with phpQuery, but it is now working

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

有人可以告诉我如何实现这一目标吗?

Can someone give me a clue on how to achieve this?

最好的问候,

推荐答案

我认为问题可能出在您使用::newDocumentFile()的phpQuery调用上.此函数需要一个文件名(不确定URL是否有效),但是我怀疑您的->getPage()实际上已经获取了该文件.如果是这样,则使用普通的::newDocument()就像这样:

I think the problem might be your phpQuery invocation with ::newDocumentFile(). This function needs a filename (not sure if an URL works), but I suspect your ->getPage() actually fetches the file already. If so, then use the normal ::newDocument() like so:

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

为我工作.

这篇关于PhpQuery如何工作?尝试获取< title>的值;标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆