从从网站抓取的链接超链接获取HTML

问题描述 投票:0回答:1

我目前正在尝试导航到另一个网页,并使用我抓取的超链接获取其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个回答
0
投票

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

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

如果curl_init中没有错误,则在每次curl函数调用之后仍然使用curl_error以获取问题的说明。

© www.soinside.com 2019 - 2024. All rights reserved.