我试图抓取一个使用浏览器正常打开的网站。然而,每当我使用cURL打开链接时,我都会进入一个中间重定向页面,显示“重定向...请等待”。
我的代码如下:
$url = "https://codeforces.com/problemset";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$result = curl_exec($ch); //returning the source code for the url.
echo $result;
而不是返回url的内容curl_exec($ch)
返回以下值:
<html>
<body>Redirecting... Please, wait.<script type="text/javascript" src="/aes.min.js"></script>
<script>
function toNumbers(d) {
var e = [];
d.replace(/(..)/g, function(d) {
e.push(parseInt(d, 16))
});
return e
}
function toHex() {
for (var d = [], d = 1 == arguments.length && arguments[0].constructor == Array ? arguments[0] : arguments, e = "", f = 0; f < d.length; f++) e += (16 > d[f] ? "0" : "") + d[f].toString(16);
return e.toLowerCase()
}
var a = toNumbers("e9ee4b03c1d0822987185d27bca23378"),
b = toNumbers("188fafdbe0f87ef0fc2810d5b3e34705"),
c = toNumbers("d797a6b5b9d48f1ca8bcbddbe6654d10");
document.cookie = "RCPC=" + toHex(slowAES.decrypt(c, 2, a, b)) + "; expires=Thu, 31-Dec-37 23:55:55 GMT; path=/";
document.location.href = "https://codeforces.com/problemset?tags=1000-1500&f0a28=1";
</script>
</body>
</html>
这将导致一个页面,其中只显示此output in browser
同样的代码在几天前已经工作了。链接仍然可以手动访问。我如何修复这个问题?
有没有办法使用cURL重定向到document.location.href
?
1条答案
按热度按时间1u4esq0p1#
cURL不能执行任何JavaScript代码。JavaScript代码在浏览器中执行。此外,这种技术的实现用于阻止不必要的Web抓取。由于您试图抓取的网站已经设置了它,因此抓取可能是非法的或对网站有害。
如果你仍然需要抓取这些网站,你可以试试selenium或者其他一些无头浏览器,或者其他专门的网页抓取工具。