如何使用DOM和XPath推断iframe中的文本内容?

时间:2018-10-17 09:38:37

标签: php dom xpath iframe domxpath

我想使用DOMXPath来推断iframe对象中消息的文本。

这是我到目前为止尝试过的:

$dom = new DOMDocument();
// We don't want to bother with white spaces
$dom->preserveWhiteSpace = false;

// Most HTML Developers are chimps and produce invalid markup...
$dom->strictErrorChecking = false;
$dom->recover = true;

$isSuccessful = @$dom->loadHTMLFile('https://t.me/Chelsea/874');

// Delay 1 second after the request to avoid getting BANNED
sleep(1);

// Check to see if URL is valid
if($isSuccessful === false)
{
    //URL invalid!
    echo "\"".$url."\" is invalid<br>";
    return false;
}

$xpath = new DOMXPath($dom);
$hrefs=$xpath->query('//*[@id="widget"]/iframe');

但是,数组的长度为0

如何推断tgme_widget_message_textiframe中的文本内容?

0 个答案:

没有答案