我正在尝试编写一个脚本,可以从我学校的日程搜索网页中检索 HTML。当我使用浏览器访问该网页时,我可以正常访问该网页,但是当我尝试使用 cURL 使其工作时,它会从重定向页面获取 HTML。当我改变
CURLOPT_FOLLOWLOCATION
从真到假的变量,它只输出一个带有标题的空白页。
作为参考,我的 PHP 代码是
<?php
$curl_connection = curl_init('https://www.registrar.usf.edu/ssearch/');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($curl_connection, CURLOPT_HEADER, true);
curl_setopt($curl_connection, CURLOPT_REFERER, "https://www.registrar.usf.edu/");
$result = curl_exec($curl_connection);
print $result;
?>
我试图从 cURL 获取 HTML 的网站是https://www.registrar.usf.edu/ssearch/或https://www.registrar.usf.edu/ssearch/search.php
有任何想法吗?