Domanda

the below one is the url where i am parsing link tags

http://www.mobileapp.pcmac.org/mobile/xml/sisapp.asp?sid=353&pn=news2

in this url the data is

 <item>
      <title>DATA WAREHOUSE (Quick link and training information)</title>
      <category> News</category>
      <description></description>
      <pubDate>Tue, 1 Dec 2009 00:00 CST</pubDate>
      <enclosure url="" length="0" type="image/jpg" />
      **<link>http://www.mcpss.com?PN=&apos;News2&apos;&amp;SubP=&apos;DNewsStory&apos;&amp;gn=&amp;NewsID=17662&amp;ShowNav=&amp;StoryGroup=Current</link>**
    </item>

i am parsing the link tag from above data.but when i tried to put that value in a below code it is throwing the following exception: HTTP error fetching URL

try {
           String website=list.get(0);
           Document doc = Jsoup.connect(website).get();
           Elements el=doc.getElementsByClass("header");
           Elements atr= doc.select("p span");
           String ss="";
           for(Element s:atr)
               ss+=s.text();
                String text=el.text();
                t1.setText(text);
                t2.setText(ss);
     } catch (Exception e) {
log.d("Error",e.getMessage());

              }

if i hard code that link value it is working fine . i need some help to solve this problem.

È stato utile?

Soluzione

First you need to check if your parsing works correctly. so use println or similar. If the url then has been confirmed you can do the next step.

Most problems occur with redirects.

In your example the parsed link would be:

http://www.mcpss.com?PN=&apos;News2&apos;&amp;SubP=&apos;DNewsStory&apos;&amp;gn=&amp;NewsID=17662&amp;ShowNav=&amp;StoryGroup=Current

The actual site being redirected to is:

http://www.mcpss.com/?PN=&apos;News2&apos;&amp;SubP=&apos;DNewsStory&apos;&amp;gn=&amp;NewsID=17662&amp;ShowNav=&amp;StoryGroup=Current

You can see that a slash has been added. Try connecting to that final url with jsoup. If that works than you need to parse all your links first and add the slash before you connect to it with jsoup. It should be a persistent scheme for all urls though if applicable.

hope it helps

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top