2011-07-11 8 views
0

ウェブページからデータ(HTMLタグ)を取得しようとしていますが、できません。何らかの理由で、私はちょうど空のタグを主に取得します。ウェブページからhtmlを読むことができません

これはURLである:http://www.miamidade.gov/transit/mobile/routes.asp

は、これは私のJavaコードです:

import java.io.IOException; 
import org.jsoup.Jsoup; 
import org.jsoup.nodes.Document; 
class xyz{ 
    public static void main (String[] args) throws IOException { 
     Document doc = jsoup.connect("http://www.miamidade.gov/transit/mobile/routes.asp").userAgent(" Mozilla/5.0").timeout(3000).post(); 
     String title = doc.html(); 
     System.out.print(title); 
    } 
} 

答えて

1

この

Document doc = Jsoup.parse("http://www.miamidade.gov/transit/mobile/routes.asp",10000); 
System.out.print(doc.toString()); 

のように試してみてください時間があなたのページ

のために十分ではない時間不足している可能性があり
+1

...それはあなたのために働くのですか?私に知らせてください... – skinnycat

+0

はい私のために働いた方法私のページでそれをテストしなかったが – Rasel

+0

それも私のために働いた...ありがとう。 – skinnycat

2

ページはhttp://www.miamidade.gov/transit/mobile/routes.aspに最初にjavascriptで "s criptCheck.asp?script = yes & CurrentPage =/transit/mobile/routes.asp? " 。その後、最終的にページに表示される情報でhttp://www.miamidade.gov/transit/mobile/routes.aspを再度読み込みます。 Jsoupはそのリダイレクトを処理しないように見えるので、コードは最初のページを取得し、ブラウザを使用するときに表示されるHTMLとは異なるHTMLを返します。おそらくあなたが期待する情報を見つけられないのかもしれません。私は動作しませんでした最初のページの

ソースコード

<html> 
<head> 
    <title></title> 
    <script language="JavaScript"> 
<!-- 
window.location="scriptCheck.asp?script=yes&CurrentPage=/transit/mobile/routes.asp?"; 
//--> 

    </script> 
</head> 
<body> 
    <noscript> 
    <meta http-equiv="Refresh" content="0;URL=scriptCheck.asp?script=no&amp;CurrentPage=/transit/mobile/routes.asp?" /> 
    </noscript> 
    <noscript> 
    <br /> 
    <br /> 
    <a href="scriptCheck.asp?script=no&amp;CurrentPage=/transit/mobile/routes.asp?">Enter MDT Mobile Services Site</a> 
    <br /> 
    <br /> 
    </noscript> 
</body> 
</html> 
+0

質問:ページがどこに直接つながっていたのか、どうやって知りましたか? – skinnycat

+0

そのページのソースコード – aldrin

+0

どのように私はあなたが見ているのと同じhtmlコードが表示されないのですか?私はクロムを使用しています – skinnycat

関連する問題