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

  • SEARCH
  • Home
  • 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 7675003
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:51:48+00:00 2026-05-31T16:51:48+00:00

I was playing with Jericho’s html parser, but I can’t find information or rather

  • 0

I was playing with Jericho’s html parser, but I can’t find information or rather an example on how to set or change user-agent. I found the class Config, but don’t know how to use it, can anyone else give me an example, please?

I managed to parse a website as I want, but I’m not sure whether Jericho’s parser adds a user agent. As you might know I want a proper user agent to prevent a site prohibits me for accessing its content.

Thank you.

  • 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-31T16:51:49+00:00Added an answer on May 31, 2026 at 4:51 pm

    Further to my comment above, make sure you always obey robots.txt. Aside from that, the code you want should look something like this.

    
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.List;
    
    import net.htmlparser.jericho.Element;
    import net.htmlparser.jericho.Source;
    
    public class HtmlFun {
    
       public static void main(String[] args) throws Exception {
          URL url = new URL("http://www.google.com");
          URLConnection conn = url.openConnection();
          conn.setConnectTimeout(1000);
          conn.setReadTimeout(1000);
          conn.setRequestProperty("User-Agent", "Mozilla");
    
          Source source = new Source(conn);
          List elems = source.getAllElements();
          for(Element elem : elems) {
             System.out.println(elem);
          }
       }
    }
    
    

    Can’t run it from work, due to firewall issues, but I think this should work for you. If not, something similar will do the trick.

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

Sidebar

Related Questions

Playing with new RTTI module, I couldn't find a way to set an event
Playing with the new(ish) url rewriting functionality for web forms, but I'm running into
been playing with this for a few hours and can't figure it out. jsFiddle
Playing with a few tutorials on sockets but struggling to connect. My tomcat server
Playing with a breakout clone and wanted to make rounded corner powerups. Can someone
Im playing around with TryParse() But lets say the parsing fails, then returns false,
Playing with Disqus for commenting, but the problem is that we have a Silverlight
I playing around with the sftp example from here: Stackoverflow: twisted conch filetransfer I
Busy playing with django, but one thing seems to be tripping me up is
Playing around with Python - tkInter - Entry widget - when I use validatecommand

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.