我试图从科学直接链接下载pdf,但是一个强制下载的链接。现在我想将它下载到我的服务器。
我有帐户,并且还使用curl将我的用户名发送到网站。
链接:
我的代码:
$url="http://www.sciencedirect.com/science/article/pii/S0254058417306235/pdfft?md5=5cf0c6dff9cab2d3678a53d25e0e1a66&pid=1-s2.0-S0254058417306235-main.pdf";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
file_put_contents("a.pdf", fopen($url, 'r'));
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13" );
curl_setopt($ch, CURLOPT_REFERER, 'https://www.sciencedirect.com/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); // Videos are needed to transfered in binary
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // That's the clue!
$redirectURL = curl_getinfo($ch,CURLINFO_HTTP_CODE);
$result = curl_exec($ch); // $result will have your video.
curl_close($ch);
但这段代码不起作用!