Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6890783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:19:34+00:00 2026-05-27T06:19:34+00:00

I am crawling a webpage and after crawling it extract all the links from

  • 0

I am crawling a webpage and after crawling it extract all the links from that webpage and then I am trying to parse all the url using Apache Tika and BoilerPipe by using below code so for some url it is parsing very well but for few XML I got the following error. I am not sure what does this error means. Some problem with my code or some problem with the XML file? And this is the below line number 100 in HTML Parser.java

String parsedText = tika.parseToString(htmlStream, md);

Error that I am having-

org.apache.tika.exception.TikaException: Invalid XML: Error on line 16: Invalid byte 1 of 1-byte UTF-8 sequence.
        at org.apache.tika.parser.feed.FeedParser.parse(FeedParser.java:75)

        at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:197)
        at org.apache.tika.parser.CompositeParser.parse(CompositeParser.java:197)
        at org.apache.tika.parser.AutoDetectParser.parse(AutoDetectParser.java:135)
        at org.apache.tika.Tika.parseToString(Tika.java:357)
        at edu.uci.ics.crawler4j.crawler.HTMLParser.parse(HTMLParser.java:101)
        at edu.uci.ics.crawler4j.crawler.WebCrawler.handleHtml(WebCrawler.java:227)
        at edu.uci.ics.crawler4j.crawler.WebCrawler.processPage(WebCrawler.java:299)
        at edu.uci.ics.crawler4j.crawler.WebCrawler.run(WebCrawler.java:118)
        at java.lang.Thread.run(Unknown Source)

HTMLParser.java code-

public void parse(String htmlContent, String contextURL) {

    InputStream htmlStream = null;
    text = null;
    title = null;
    metaData = new HashMap<String, String>();

    urls = new HashSet<String>();
    char[] chars = htmlContent.toCharArray();

    bulletParser.setCallback(textExtractor);
    bulletParser.parse(chars);

    try {
        text = articleExtractor.getText(htmlContent);
    } catch (BoilerpipeProcessingException e) {
        e.printStackTrace();
    }

    if (text == null){
        text = textExtractor.text.toString().trim(); 
    }

    title = textExtractor.title.toString().trim();
    try {
        Metadata md = new Metadata();
        htmlStream = new ByteArrayInputStream(htmlContent.getBytes());
        String parsedText = tika.parseToString(htmlStream, md);
        //very unlikely to happen
        if (text == null){
            text = parsedText.trim();
        }
        processMetaData(md);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        IOUtils.closeQuietly(htmlStream);
    }
    bulletParser.setCallback(linkExtractor);
    bulletParser.parse(chars);
    Iterator<String> it = linkExtractor.urls.iterator();

    String baseURL = linkExtractor.base();
    if (baseURL != null) {
        contextURL = baseURL;
    }

    int urlCount = 0;
    while (it.hasNext()) {
        String href = it.next();
        href = href.trim();
        if (href.length() == 0) {
            continue;
        }
        String hrefWithoutProtocol = href.toLowerCase();
        if (href.startsWith("http://")) {
            hrefWithoutProtocol = href.substring(7);
        }
        if (hrefWithoutProtocol.indexOf("javascript:") < 0
                && hrefWithoutProtocol.indexOf("@") < 0) {
            URL url = URLCanonicalizer.getCanonicalURL(href, contextURL);
            if (url != null) {
                urls.add(url.toExternalForm());
                urlCount++;
                if (urlCount > MAX_OUT_LINKS) {
                    break;
                }   
            }               
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:19:34+00:00Added an answer on May 27, 2026 at 6:19 am

    Try changing

    htmlStream = new ByteArrayInputStream(htmlContent.getBytes());
    

    to

    String utfHtmlContent = new String(htmlContent.getBytes(),"UTF-8")
    htmlStream = new ByteArrayInputStream(utfHtmlContent.getBytes());
    

    This may be a hack and you may not want to use it as your final solution, but it if it starts to work after this change you will know that the input was not originally UTF-8.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am crawling a page www.thenextweb.com I want to extract all the post links,
hi all I'm writing a simple web crawling script that needs to connect to
I'm trying to set the URL to follow the AJAX crawling scheme as described
I am trying to create a simple web crawler using PHP that is capable
I'm crawling a website using php. As I don't know much about turning php
I'm trying to test Scrapy for crawling web pages and I do not understand
I am using nutch 1.4 to crawl websites. For demo purpose, I started crawling
My task is crawling the google search results using headless webkit(PyQt4.QtWebkit) in python. The
I am currently working on a project that involves crawling certain websites. However sometimes
I recently wrote a java crawler program that finds the video links in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.