Re: [問題] 如何取得html標籤中的值??
httpunit 也很好用喔!!
http://httpunit.sourceforge.net/
try it!!!
※ 引述《feicsh.bbs@bbs.wretch.cc (飛)》之銘言:
: Pattern pattern = Pattern.compile("href=\"[^\"]*");
: Matcher m = pattern.matcher(sb.toString());
: while(m.find()) {
: String str = m.group();
: str = str.replaceFirst("href=\"", "");
: str = str.substring(0, str.length()-1);
: System.out.println(str);
: }
: Instead of regular expression,
: HTML parser might be the more appropriate and pretty solution.
: If you are interested, read this site http://htmlparser.sourceforge.net/
: ※ 引述《keyairotika.bbs@ptt.cc (空白之才)》之銘言:
: > import java.util.regex.*;
: > import java.io.*;
: > public class Test1 {
: > public static void main(String[] args) throws Exception {
: > StringBuffer sb = new StringBuffer();
: > BufferedReader br = new BufferedReader(new FileReader("c:/work/112.txt"));
: > String line="";
: > while( (line=br.readLine()) != null) {
: > sb.append(line);
: > }
: > Pattern pattern = Pattern.compile(" "); //裡面要怎麼用才能把我要的網址抽出來?
: > Matcher m = pattern.matcher(sb.toString());
: > while(m.find()) {
: > String str = m.group();
: > System.out.println(str);
: > }
: > }
: > }
: > 假設在infile.txt裡面有內容如下
: > <a class=l href="http://www.ntnu.edu.tw/art/" onmousedown="
: > <a class=l href="http://203.71.53.40/" onmousedown="
: > <a class=l href="http://www.scdxart.com/" onmousedown="return
: > 我只想要裡面的網址如下
: > http://www.ntnu.edu.tw/art/
: > http://203.71.53.40/
: > http://www.scdxart.com/
: > Pattern pattern = Pattern.compile(" ");
: > 這行裡面要怎麼用
: > 我現在只弄到這樣 但還是不對
: > Pattern pattern = Pattern.compile("http://[^\"\\s]+");
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.236.102.99
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 3 篇):