如何在解析Google-trends html响应时删除状态203错误?

时间:2014-08-26 12:29:56

标签: java youtube html-parsing trending google-trends

点击网址后,我通过html响应获取 Google趋势数据。我设法通过Jsoup库解析该响应。我得到的数据只有3-4次。之后它开始给出Status-203错误。每天我运行此代码3-4次后我得到了这个异常。请帮帮我,我现在该怎么办? 我的代码是 -

public class HTMLParser {

private static HashMap<String, HashMap<String, String>> hostcokkies = new HashMap<String, HashMap<String,String>>();

public static ArrayList<HotTrends> getYouTubeTrendings()
{
    Document document;
    ArrayList<HotTrends> list = new ArrayList<HotTrends>();
    HotTrends trends          = null;
    try {
    document        =   Jsoup.connect("http://www.google.com/trends/fetchComponent?geo=IN&date=today+12-m&gprop=youtube&cmpt=q&cid=TOP_QUERIES_0_0").get();
    Elements links  =   document.select("a[href]");
      for(Element link : links){
          trends    =   new HotTrends();
          trends.setWord(link.text());
          list.add(trends);
      }
    }
    catch(Exception e)
    {
        e.printStackTrace();
    }
    return list;
}

public static void main(String args[])
{
    ArrayList<HotTrends> hotTrends = new ArrayList<HotTrends>();
    hotTrends   =    HTMLParser.getYouTubeTrendings();
    for(HotTrends trends : hotTrends)
    {
        System.out.println(trends.getWord());
    }   
}

}

1 个答案:

答案 0 :(得分:1)

我遇到同样的问题,只需自己更改您的IP地址或使用程序(我使用Hotspot Shield http://www.hotspotshield.com/)它对我有效