【问题标题】:Getting the HTML from a link hyperlink scraped from a website从网站抓取的链接超链接获取 HTML
【发布时间】:2020-06-30 23:44:25
【问题描述】:

我目前正在尝试导航到另一个网页,并使用我抓取的超链接获取其 HTML。 (我需要存储在上面的信息)。

我目前无法让 PHP curl 函数使用我生成的链接获取 HTML 代码。

我试图用来构建/获取 HTML 代码的代码部分是:

foreach($rows as $row)
{
    //creating the link itself. https://pr.mo.gov/ is the website itself, the attribute that is returend is the direction location.
    // /pharmacy-licensee-search-detail.asp?passkey=1285356, us an example of what I get from getArrtibute('href')
    $holder = "https://pr.mo.gov/".$row->getAttribute('href');
    // $holder = https://pr.mo.gov/pharmacy-licensee-search-detail.asp?passkey=1285356 as per the example used in the comments above.
    echo $holder;
    echo "<br>";

    //trying to use curl to get the website html
    $c = curl_init("$holder");
    $html2 = curl_exec($c);
    //Trying to print out what has been recived
    echo var_dump($html2); 
    //IT's printing out bool(false)
    curl_close($c);
}

这部分之前的代码工作正常——因为它从原始网页中获取了 HTML。如果需要,我会发布。

【问题讨论】:

  • 有什么问题?

标签: php parsing curl web-scraping screen-scraping


【解决方案1】:

您需要检查curl_init 调用的结果。

在其后添加echo curl_error($c) . "&lt;br&gt;"; 以查看错误。很可能与 SSL 证书有关。如果是这样,看看这个问题 - PHP - SSL certificate error: unable to get local issuer certificate

如果 curl_init 没有错误,在每次 curl 函数调用后使用curl_error 得到问题解释。

【讨论】:

  • 添加 curl_exec 确实会给我一个 SSL 证书错误。我该如何解决这个问题?
猜你喜欢
  • 1970-01-01
  • 2021-03-31
  • 1970-01-01
  • 2020-02-09
  • 1970-01-01
  • 1970-01-01
  • 2016-11-28
  • 2017-06-30
  • 1970-01-01
相关资源
最近更新 更多