简体   繁体   English

设置 cookie 抛出 curl 请求

[英]set cookie throw curl request

I want to set cookie throw curl request.我想设置 cookie throw curl 请求。 I used this code but the requested URL return You must enable Javascript and accept cookies.我使用了此代码,但请求的 URL 返回You must enable Javascript and accept cookies. what Im doing wrong here?我在这里做错了什么?

cookie.txt file is 0644 permission cookie.txt文件是 0644 权限

$curl = curl_init();
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_URL, $base);
curl_setopt ($curl, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($curl, CURLOPT_REFERER, $base);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$str = curl_exec($curl);
curl_close($curl);

The problem is not your code, it's that the page you're trying to access works only by executing javascript.问题不在于您的代码,而在于您尝试访问的页面只有通过执行 javascript 才能工作。 CURL doesn't support that, it just downloads the HTML code of the page, but doesn't execute any javascript. CURL不支持,它只是下载页面的 HTML 代码,但不执行任何 javascript。

If you're in the need of retrieving information from a website that needs to execute javascript, you need to rely on solutions that provide headless browsers, like Selenium如果您需要从需要执行 javascript 的网站检索信息,则需要依赖提供无头浏览器的解决方案,例如Selenium

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM