为什么我的 jsoup.connect(url) 无法使用某些 url?

问题描述 投票:0回答:2

我正在尝试从 http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id=CH06

获取标题

这是我的源代码的一部分:

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
这样的url一起使用,为什么呢?

java jsoup
2个回答
1
投票

默认情况下,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>

正如我所说:Jsoup 不支持 javascript,并且不会被重定向到这里。

顺便说一句。您确实需要连接到此链接吗?它唯一做的就是重定向到 home 页面。所以也许你的网址无效。


0
投票

此网站

http://tv.atmovies.com.tw/tv/attv.cfm?action=channeltime&channel_id=CH06
”重定向至
http://www.atmovies.com.tw/home/

© www.soinside.com 2019 - 2024. All rights reserved.