1
我試圖解析一些使用perl模塊Web ::刮板的HTML標籤,但似乎我無法使用perl。我不知道是否有人可以看看我的代碼中的錯誤...:使用Web ::刮板
這是我的HTML解析(2個網址內李標籤):
<more html above here>
<div class="span-48 last">
<div class="span-37">
<div id="zone-extract" class="123">
<h2 class="genres"></h2>
<li><a href="**URL_TO_EXTRACT_1**">1</a></li>
<li><a class="sel" href="**URL_TO_EXTRACT_2**">2</a></li>
<li class="first">Pàg</li>
</div>
</div>
</div>
<more stuff from here>
我試着去獲得:
ID:1鏈路:URL_TO_EXTRACT_1
ID:2鏈接:URL_TO_EXTRACT_2
有了這個Perl代碼:
my $scraper = scraper {
process ".zone-extract > a[href]", urls => '@href', id => 'TEXT';
result 'urls';
};
my $links = $scraper->scrape($response);
這是無限過程組合我嘗試,與兩個不同的結果中的一個:一個空的返回,或內部碼的所有網址(我只需要內部區域的提取物鏈接)。
解決了與暴民的貢獻...#區提取物代替.zone提取物:)
在上一集:http://stackoverflow.com/a/9821254/46395 – daxim 2012-03-22 19:20:38
難道不是對'class =「zone-extract」'屬性的元素使用't'.zone-extract'?對於'id =「zone-extract」'我想你會想要'#zone-extract',不是嗎? – mob 2012-03-22 19:24:43
謝謝暴徒你是對的,它現在可行! :P – Courier 2012-03-22 19:35:37