Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从外部站点检索div的内容_Php_Wordpress_Xpath - Fatal编程技术网

Php 从外部站点检索div的内容

Php 从外部站点检索div的内容,php,wordpress,xpath,Php,Wordpress,Xpath,尝试使用g PHP和XPath从外部站点检索div的内容 这是该页面的摘录,显示了相关代码: 注意:我尝试在类中添加all,并在查询的末尾添加@,然后使用saveHTML()获取它。参见我的测试: 顺便说一句: this is my XPath: //*[@id="post-15991"]/div[4]/div[1] this is the URL: https://wordpress.org/plugins/wp-job-manager/ 请参阅后续代码: <?PHP $url =

尝试使用g PHP和XPath从外部站点检索div的内容

这是该页面的摘录,显示了相关代码: 注意:我尝试在类中添加all,并在查询的末尾添加@,然后使用saveHTML()获取它。参见我的测试:

顺便说一句:

this is my XPath:  //*[@id="post-15991"]/div[4]/div[1]
this is the URL: https://wordpress.org/plugins/wp-job-manager/
请参阅后续代码:

<?PHP
$url = 'https://wordpress.org/plugins/wp-job-manager/';
$dom = new DOMDocument();
@$dom->loadHTMLFile($url);
$xpath = new DOMXpath($dom);
$elements = $xpath->query('//*[@id="post-15991"]/div[4]/div[1]');
$link = $dom->saveHTML($elements->item(0));
echo $link;
?>
目标:我需要以下数据:

Version:
Last updated:
Active installations:
Tested up
例如,请参见以下-查看源:

  • 版本:1.29.3
  • 上次更新:5天前
  • 活动安装:100000+
  •                     <li>
            Requires WordPress Version:<strong>4.3.1</strong>                </li>
    
                        <li>Tested up to: <strong>4.9.2</strong></li>
    
    及 工作委员会经理:

    //*[@id="post-519"]/div[4]/div[1]/ul/li[1]
    //*[@id="post-519"]/div[4]/div[1]/ul/li[2]
    //*[@id="post-519"]/div[4]/div[1]/ul/li[3]
    //*[@id="post-519"]/div[4]/div[1]/ul/li[7]
    
    我用了这个方法:


    您正在调用
    .loadHTMLFile
    ,它需要一个文件路径。如果打开了警告选项,您将看到以下警告:

    E_警告:类型2--DOMDocument::loadHTMLFile():在中重新定义的属性类,第190行--第5行

    E_警告:类型2--DOMDocument::loadHTMLFile():中的标记头无效,第201行--第5行

    E_警告:类型2--DOMDocument::loadHTMLFile():标记导航在中无效,第205行--第5行

    E_警告:类型2--DOMDocument::loadHTMLFile():标记main在中无效,第224行--在第5行

    相反,请使用
    .loadHTML

    $url = 'https://wordpress.org/plugins/wp-job-manager/';
    $dom = new DOMDocument();
    @$dom->loadHTML($url);
    $xpath = new DOMXpath($dom);
    $elements = $xpath->query('//*[@id="post-15991"]/div[4]/div[1]');
    $link = $dom->saveHTML($elements->item(0));
    echo $link;
    
    结果是:

    https://wordpress.org/plugins/wp-job-manager/
    

    您好,再见-非常感谢-查看原始帖子和我的**目标**:我想要数据:
    Last updated:Active installations:Tested up
    查看以下示例-查看源代码:`Version:1.29.3 Last updated:5天前Active installations:100000+`如何检索这些结果?
    Right click "inspect" on the item you are trying to find the xpath
    Right click on the highlighted area on the console.
    Go to Copy xpath
    
    $url = 'https://wordpress.org/plugins/wp-job-manager/';
    $dom = new DOMDocument();
    @$dom->loadHTML($url);
    $xpath = new DOMXpath($dom);
    $elements = $xpath->query('//*[@id="post-15991"]/div[4]/div[1]');
    $link = $dom->saveHTML($elements->item(0));
    echo $link;
    
    https://wordpress.org/plugins/wp-job-manager/