Php 使用DOM爬虫从url获取元标记
我已经在我的项目中安装了Php 使用DOM爬虫从url获取元标记,php,symfony,dom,meta-tags,domcrawler,Php,Symfony,Dom,Meta Tags,Domcrawler,我已经在我的项目中安装了symfony/dom crawler。 我试图从一些随机站点的URL中获取一些元标记进行测试 $url = 'https://www.lala.rs/fun/this-news'; $crawler = new Crawler($url); $data = $crawler->filterXpath("//meta[@name='description']")->extract(array('content')); 结果总是返回[]
symfony/dom crawler
。
我试图从一些随机站点的URL中获取一些元标记进行测试
$url = 'https://www.lala.rs/fun/this-news';
$crawler = new Crawler($url);
$data = $crawler->filterXpath("//meta[@name='description']")->extract(array('content'));
结果总是返回[]
我尝试过基本的元描述,但可能我不理解它的权利。
我检查了,但找不到正确的方法。您需要将HTML内容传递给新的爬虫程序($HTML),而不是URL 由于缺少
说明
,因此在此页面上使用视口
可以正常工作
给
Array
(
[0] => width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0
)
$url = 'https://stackoverflow.com/questions/66494027/get-meta-tags-from-url-with-dom-crawler';
$html = file_get_contents($url);
$crawler = new Crawler($html);
$data = $crawler->filterXpath("//meta[@name='viewport']")->extract(['content']);
Array
(
[0] => width=device-width, height=device-height, initial-scale=1.0, minimum-scale=1.0
)