我在寫一個perl腳本,它從html文件中獲取數據。我可以使用WWW::Mechanize
輕鬆導航到頁面並打印輸出文件。然而,我需要獲得的數據是一個iframe標籤,並具有動態的src值。使用Perl從html文件加載iframe標記的數據
我也想出了一個想法,使用XML::Parser
,因爲我有網站的XML API。但是,由於我的noobness,我不知道如何獲得XML鏈接。
所以我的問題是:
第1頁:如何顯示或iframe標籤獲取數據
第二:如何獲得從一個網站XML鏈接。
這是我的代碼
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
use XML::Simple;
use WWW::Mechanize;
use HTTP::Cookies;
use LWP::Debug qw(+);
my $username = $opt_u;
my $password = $opt_p;
my $outfile = "out.html";
my $url = "https://t-square.gatech.edu/portal";
my $mech = WWW::Mechanize->new();
$mech->cookie_jar(HTTP::Cookies->new());
$mech->get($url);
$mech->follow_link(text => "Login", n => 1);
$mech->submit_form(
form_id=> 'fm1',
fields => { username => $username,
password => $password
},
button => 'submit',
);
$mech->follow_link(text => "CS-2200-A,GR SUM13", n => 1);
my $response = $mech->follow_link(text => "Assignments", n => 1);
$response = $mech->get('https://t-square.gatech.edu/portal/tool/3a34f619-99d1-4548-be57- 9ee977fd8127?panel=Main');
my $content = $response->decoded_content();
my $parser = new XML::Simple;
my $data = $parser->XMLin($content);
print Dumper($data);
my $output_page = $mech->content();
open(OUTFILE, ">$outfile");
print OUTFILE "$output_page";
close(OUTFILE);
這裏是一塊從我out.htm輸出其中FRAME SRC位於的。
...
<iframe name="Main3a34f619x99d1x4548xbe57x9ee977fd8127"
id="Main3a34f619x99d1x4548xbe57x9ee977fd8127"
title="Assignments "
class ="portletMainIframe"
height="475"
width="100%"
frameborder="0"
marginwidth="0"
marginheight="0"
scrolling="auto"
src="https://t-square.gatech.edu/portal/tool/3a34f619-99d1-4548-be57-9ee977fd8127?panel=Main">**
</iframe>
...
我需要的數據是在幀標籤內的src鏈接。
謝謝。
我們需要一些例子 – Suic
什麼是「動態的SRC值」? – Quentin
如果有一個API,那麼你應該*絕對*使用它來刮取HTML。 「獲取XML鏈接」是什麼意思? – Quentin