作者LinusChen (來如春夢不多時)
看板perl
標題[問題] 抓取網頁中的pdf檔案
時間Thu Nov 30 00:07:49 2006
我想要抓取某個網頁中的PDF檔案
PDF產生的方式是先傳序號給該網址
我使用
use IO::Socket;
print $socket "GET Query.aspx?pn=00525881&imageindex=1 HTTP/1.1\r\n";
而它顯示的網頁有html和pdf
我該如何把pdf存下來啊?
#Server Response
$result = "";
while (my $line=<$socket>) {
$result .= $line;
}
#HTTP Server Response Header
$result = substr($result,index($result,"\x0d\x0a\x0d\x0a")+4);
#存檔
open F, "> PDF_file" or die "Can't write into filename";
print F $result;
close F;
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.109.18.90
推 in2:use LWP::Simple;use IO::All; 12/02 12:02
推 in2:疑, 搞錯了, 妳應該需要 cookie 一類的東西吧 :p 12/02 12:04
推 LinusChen:可能是需要cookie吧 但是還是不知道怎麼做 我嘗試用lynx 12/04 14:58
→ LinusChen:去開那個網頁 結果也沒有辦法下載pdf檔 12/04 15:00
→ LinusChen:lynx本身有支援cookie 12/04 15:01