Java 为什么我的jsoup.connect(url)不能与某些url一起工作?
我正试着从我的书名中取回书名 以下是我的源代码部分:Java 为什么我的jsoup.connect(url)不能与某些url一起工作?,java,jsoup,connect,Java,Jsoup,Connect,我正试着从我的书名中取回书名 以下是我的源代码部分: Document doc = Jsoup.connect( theurl above ).get(); Element title = doc.select("title"); textview.setText(title); 当我试图从www.yahoo.com获取标题时,此代码可以工作。 但是它不能像http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id
Document doc = Jsoup.connect( theurl above ).get();
Element title = doc.select("title");
textview.setText(title);
当我试图从www.yahoo.com
获取标题时,此代码可以工作。
但是它不能像
http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id=CH06
为什么会这样?这个网站http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id=CH06
“重定向到http://www.atmovies.com.tw/home/
默认情况下,Jsoup如下。但是,重定向的方式可能会导致您的问题。如果网站为此使用javascript,连接将不会被重定向,因为jsoup不支持javascript
这似乎就是原因
测试代码:
Document doc = Jsoup.connect("http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id=CH06").get();
System.out.println(doc);
<html>
<head>
<script language="javascript">if (top.frames.length != 0) { top.location = self.document.location; }</script>
<meta http-equiv="Refresh" content="0;URL=/home/" />
</head>
<body></body>
</html>
输出:
Document doc = Jsoup.connect("http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id=CH06").get();
System.out.println(doc);
<html>
<head>
<script language="javascript">if (top.frames.length != 0) { top.location = self.document.location; }</script>
<meta http-equiv="Refresh" content="0;URL=/home/" />
</head>
<body></body>
</html>
如果(top.frames.length!=0){top.location=self.document.location;}
正如我所说:Jsoup不支持javascript,也不会在这里重定向
顺便问一下,你真的需要连接到这个链接吗?它唯一能做的就是重定向到主页。因此,您的url可能无效。谢谢您这么快回复,但如何解决重定向问题?