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 8604267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:31:50+00:00 2026-06-12T02:31:50+00:00

<div></div> <div></div> <div></div> <div></div> <ul> <form id=the_main_form method=post> <li> <div></div> <div> <h2> <a onclick=xyz;

  • 0
<div></div>
    <div></div>
           <div></div>
            <div></div>
                <ul>
        <form id=the_main_form method="post">
                   <li>
                       <div></div>
                       <div> <h2> 
                <a onclick="xyz;" target="_blank" href="http://sample.com" style="text-decoration:underline;">This is sample</a>
                 </h2></div>
                       <div></div>
                        <div></div>
                      </li>

there are 50 li’s like that

I have posted the snip of the html from a big HTML.

<div> </div> => means there is data in between them removed the data as it is not neccessary.

I would like to know how the JSOUP- select statement be to extract the href and Text?

I selected doc.select(“div div div ul xxxx”);

where xxx is form ..shoud I give the form id (or) how should I do that

  • 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-06-12T02:31:51+00:00Added an answer on June 12, 2026 at 2:31 am

    Try this:

    Elements allLis = doc.select("#the_main_form > li ");
    for (Element li : allLis) {
        Element a = li.select("div:eq(1) > h2 > a");
        String href = a.attr("href");
        String text = a.text();
    }
    

    Hope it helps!

    EDIT:

    Elements allLis = doc.select("#the_main_form > li ");
    

    This part of the code gets all <li> tags that are inside the <form> with id #the_main_form.

    Element a = li.select("div:eq(1) > h2 > a");
    

    Then we iterate over all the <li> tags and get <a> tags, by first getting <div> tags ( the second one inside all <li>s by using index=1 -> div:eq(1)) then getting <h2> tags, where our <a> tags are present.

    Hope you understand now! 🙂

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

Sidebar

Related Questions

<form id=Form1 method=post runat=server> <uc1:PageHeaderDisplay id=pageHeaderDisplay1 runat=server></uc1:PageHeaderDisplay> <asp:HiddenField runat=server ID=postedFormData /> <div style=display: none;
I have some jsp page manage.jsp and form inside it: <form method=POST action=./manage.form> <div
I have set the target of the pic_form to a div (pic_target). The form
Consider the following: <form runat=server> <div> <asp:TextBox runat=server ID=tb1 /> <asp:Button runat=server ID=b1 OnClick=b1_Click
<html> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8/> <meta name=layout content=main /> </head> <body> <div class=nav>
Here is my code in my ask.haml file: %form{:action => /calendar, :method => post}
I'm receiving this HTML document via AJAX: <form enctype=multipart/form-data method=POST action=admin.php?do=media&action=file-upload> <div id=uploadForm> <div
I have below html code in one of the opensource project. <form action=/wiki/bin/view/Main/Search> <div
I would like it that when the user clicks out of the #email-form div,
I have a html page with a form. The form has Div which gets

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.