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



我目前正在尝试导航到另一个网页,并使用我抓取的超链接获取其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。如果需要的话,我会贴出来。

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

在其后面添加echo curl_error($c) . "<br>";以查看错误。很可能与SSL证书有关。如果是这样的话,看看这个问题-PHP-SSL证书错误:无法获得本地颁发者证书

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

最新更新