Results 1 to 4 of 4

Thread: Jsoup help

  1. #1
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Jsoup help

    I'm trying to get some text from a class but there are more then one classes with the same name and it gives me the text from all the classes... how do I get text from a specific class?

  2. #2
    sehudson's Avatar
    sehudson is offline Senior Member
    Join Date
    Mar 2010
    Posts
    364
    Rep Power
    5

    Default Re: Jsoup help

    Does the element you are targeting have an id that you can select on?

  3. #3
    mbschultz97 is offline Super OP Noob
    Join Date
    May 2014
    Location
    Virginia
    Posts
    65
    Rep Power
    0

    Default Re: Jsoup help

    Quote Originally Posted by sehudson View Post
    Does the element you are targeting have an id that you can select on?
    No it doesn't... it only has classes and there are 3 classes with the same name so it gives me all the crap from the 3 classes.

  4. #4
    jashburn is offline Senior Member
    Join Date
    Feb 2014
    Posts
    219
    Rep Power
    1

    Default Re: Jsoup help

    This is where you may need to use a selector in order to get to the element containing the desired text. See my previous reply below. Make use of the cookbook on "Use selector-syntax to find elements" as well as the Selector API documentation.

    Quote Originally Posted by jashburn View Post
    It depends on what you want to look for. If you're lucky the data to extract is contained within an element with an ID like the one you found. If not, you may need to use the CSS/jQuery-like syntax to select the branch of elements to arrive to the unique destination containing the required data.

    The cookbook is a good place to start. See also the Selector API documentation.

    Using Chrome, the simplest way to get to the relevant line of HTML code containing the required data is to highlight the data in the browser, then right-click > Inspect Element. E.g., doing this on the "Exchange: NASDAQ" text on the web page opens up Chrome's Elements window, automatically drilling into
    Java Code:
    <span id="qbar_exchangeLabel">
        <b>Exchange: </b>
        "NASDAQ"
    </span>
    If you select "NASDAQ" on the Elements window, notice that on the status bar at the bottom of the window shows the progression of HTML elements leading up to "NASDAQ":
    Java Code:
    html  #body  ...  span#qbar_exchangeLabel  (text)
    At this point you have the choice of using either the DOM methods (e.g., getElementById(id)) or to use a selector (e.g., select(selector), making use of the progression of HTML elements to help you formulate your selector string) to get to the text contained here.

Similar Threads

  1. How to get images from Jsoup
    By mbschutlz97 in forum New To Java
    Replies: 4
    Last Post: 05-14-2014, 04:44 PM
  2. Jsoup help
    By mbschultz97 in forum New To Java
    Replies: 7
    Last Post: 05-12-2014, 04:25 AM
  3. scraping using Jsoup
    By gvs048 in forum New To Java
    Replies: 12
    Last Post: 06-07-2013, 10:00 AM
  4. jsoup 1.7.2
    By java software in forum Java Software
    Replies: 0
    Last Post: 02-01-2013, 07:05 AM
  5. jsoup 1.6.2
    By java software in forum Java Software
    Replies: 0
    Last Post: 04-02-2012, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •