我想要从URL下载页面,足够简单。但在第一个页面,我必须登录,就像我通常在普通浏览器上所做的那样。但是HTTrack是从第一个页面下载的,因为它不能使用我的cookie或登录。
我有没有办法绕过这个问题呢?
发布于 2019-10-12 20:17:21
这个问题是在2013年提出的,所以我不知道当时Httrack是否支持cookie,但现在它肯定支持。
使用说明:
您可以安装扩展或使用开发人员工具,如下所示:
火狐:F12 -> Storage -> Cookies
Chrome:F12 -> Application -> Storage -> Cookies
Httrack的cookie.txt示例:
www.httrack.com TRUE / FALSE 1999999999 foo bar
www.example.com TRUE /folder FALSE 1999999999 JSESSIONID xxx1234
www.example.com TRUE /hello FALSE 1999999999 JSESSIONID yyy1234参考:http://httrack.kauler.com/help/Cookies
发布于 2013-12-04 06:24:58
尝试在PHP中使用cURL:
http://php.net/manual/en/book.curl.php
这里有一些包装器,比如:
http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading
使用以下选项:
编辑:更具体,未测试
从以下位置下载类:
http://semlabs.co.uk/journal/object-oriented-curl-class-with-multi-threading
require_once( 'CURL.php' ); //Change this to whatever that class is called in the above
$curl = new CURL();
$curl->retry = 2;
$opts = array(
CURLOPT_USERAGENT => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20091020 Linux Mint/8 (Helena) Firefox/3.5.3',
CURLOPT_COOKIEFILE => 'fb.tmp',
CURLOPT_COOKIEJAR => 'fb.tmp',
CURLOPT_FOLLOWLOCATION => 1,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_TIMEOUT => 20
);
$post_data = array( ); //put your login POST data here
$opts[CURLOPT_POSTFIELDS] = http_build_query( $post_data );
$curl->addSession( 'https://www.facebook.com/messages', $opts );
$result = $curl->exec();
$curl->clear();
print_r( $result );请注意,有时您需要先加载一个页面,以设置cookie,然后他们才会允许您登录。
https://stackoverflow.com/questions/20362821
复制相似问题