?? thiefparse520music.java
字號:
package org.tools.plugin;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import javax.swing.JLabel;
import org.tools.DownBatch520MusicThread;
import org.tools.Thief;
public class ThiefParse520Music extends ThiefParseBase{
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
ThiefParse520Music t = new ThiefParse520Music();
t.parse("http://www.520music.com", "http://wma.520music.com", "http://www.520music.com/MusicList/520music.com_9124.htm");
}
public void doDownload(JFrame frame, Map<String, String> map, JLabel state_label, String saveto) {
// TODO 自動生成方法存根
new Thread(new DownBatch520MusicThread(map,saveto,state_label)).start();
}
public Map<String, String> parse(String homeUrl, String musicPrix, String listUrl) {
// 以下取得當前URL文檔內容
Thief thief = new Thief();
String content = thief.readURL(listUrl, null);
//content = test1;
if (content == null || content.equals(""))
return null;
//System.out.println(content);
Map<String, String> map = new HashMap<String, String>();
// 分析內容
Pattern p = Pattern.compile("type=\"checkbox\"\\s+value=\"(\\d+)\"",Pattern.CASE_INSENSITIVE),
p1 = Pattern.compile("param\\s+name=\"filename\"\\s+value=\"([^\"]+)\"",Pattern.CASE_INSENSITIVE),
p2 = Pattern.compile("target=_blank''c''>([^\\\\<]+)</a>");
Matcher m = p.matcher(content),m1,m2=p2.matcher(content);
while (m.find()) {
String musicUrl = homeUrl +"/play/"+m.group(1)+".htm";
String musicName = null;
int index = m.start(1);
if(m2.find(index))
musicName = m2.group(1).replaceAll(" ", " ");
System.out.println("讀取頁面"+musicUrl);
String __content = thief.readURL(musicUrl, null);
m1 = p1.matcher(__content);
if(m1.find()&&musicName!=null){
map.put(musicName,m1.group(1));
System.out.println("得到地址:"+musicName+"|"+m1.group(1));
}
}
return map;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -