Php 检查谷歌有机搜索结果中的域名位置
我正在使用Php 检查谷歌有机搜索结果中的域名位置,php,search,xpath,Php,Search,Xpath,我正在使用phpxpath进行解析 如何在谷歌中只获取有机搜索结果 我试过 // Grab the Google page using the chosen keywords $html = new DOMDocument(); @$html->loadHtmlFile('https://www.google.com/search?q='.$keywords.'&num=100&gl=us'); $xpath = new DOMXPath($html); // Store
phpxpath
进行解析
如何在谷歌中只获取有机搜索结果
我试过
// Grab the Google page using the chosen keywords
$html = new DOMDocument();
@$html->loadHtmlFile('https://www.google.com/search?q='.$keywords.'&num=100&gl=us');
$xpath = new DOMXPath($html);
// Store the domains to nodes
$nodes = $xpath->query('//div[@class]/cite[@class]');
但我得到的结果是空的
我还尝试了//cite[@class]
,但没有得到预期的结果
需要帮助。以下解决方案适合我
$nodes = $xpath->query("//div[1]/div[@class='kv']/cite");
它在解析时排除了无机结果。我相信谷歌现在是通过JS和AJAX加载结果的,所以你的loadHtmlFile将返回基本的Google页面而没有结果。您需要一些东西,在javascript运行完成此操作后,可以将页面带回。@JonStirling,谢谢。所以我需要找?你能告诉我更多关于这个的情况吗。