【发布时间】:2018-06-22 10:20:47
【问题描述】:
我正在尝试检查是否可以读取网页的<html> 属性以获取所有者声明的语言。
在我检查的 99% 的网站中,我发现该信息写为 <html lang="XX"> 或 <html lang="XX-YY">,但在 1 个特定网站中,我发现它写为 <html xml:lang="XX">,最后一种情况让我头疼。
我试过了
$scraper_client = new \Goutte\Client();
$scraper_crawler = $scraper_client->request('GET', $link);
$response = $scraper_client->getResponse();
var_dump( $scraper_crawler->filter('html')->extract('xml:lang')) );
var_dump( $scraper_crawler->filter('html')->extract('xml|lang')) );
var_dump( $scraper_crawler->filter('html')->extract('xml::lang')) );
var_dump( $scraper_crawler->filter('html')->extract('@[xml:lang]')) );
但它们似乎都不起作用。有人已经做过类似的事情了吗? 先感谢您。 S.
编辑
为了完成这个问题,这里有一个链接,其中包含导致我出现问题的 xml:lang 属性:
【问题讨论】: