Below mentioned two urls:

How can I get XPath after player summary content.

  • 1st url is XPath div is 4
  • 2nd url is XPath div is 5

I have tried this expression:


but am not able to find the div element.

  • Am I correct in understanding that, for the first page you provided, you want to get the text starting with "St. Louis Blues" and extending all the way down to "D. Savard D"? In other words, you are trying to collect all the data describing the player info for the game? Commented Apr 7, 2017 at 18:46

3 Answers 3


From my understanding of what you are looking for, here is an XPath that should work.

//h4[text()='Player Summary']/../../div[@class='mod-content']

First, we located the Player Summary header:

//h4[text()='Player Summary']

Then, from that node, we navigate up to the parent div for that section of the page. The following gets the parent's parent (grandparent) node:


Finally, we located the child that contains the player data:


This method is easier and more precise than trying to get the "next div after" the one with the player summary header.

Try this out in using Chrom Dev Tools. In the console, enter the following:

$x("//h4[text()='Player Summary']/../../div[@class='mod-content']")[0].textContent

Here is the result I got:

"St. Louis BluesPlayer G A PN PIMR. Bortuzzo D 0012K. Brodziak C 1000J. Doty C 0015J. Edmundson D 0012L. Ferraro C 0100T. Galiardi LW1100J. Kyrou C 1100A. Musil C 0012E. Nystrom LW1100M. Paajarvi LW0100T. Rattie RW1000Y. Stastny C 0100S. Vaughan RW0015Columbus Blue JacketsPlayer G A PN PIMK. Aulie D 0012M. Calvert LW0000B. Gallant LW0015S. Ruopp D 0015D. Savard D 0012"

Is that the text you were looking for?


When you want to specify a number of div put the [#] after the xpath for it.


I'm not exactly sure what you are after though as it looks like those are all hyperlinks with specific names in there based on the pages that you linked in. Please be very specific and include the html in question for what you are trying to do in order to get a more specific answer.

Edit based on clarification: So this gets a little tricky, but the best way to find it consistently is relationally. This is complex and I haven't had time to fully try it out to ensure the syntax is 100% but this is the theory, if I have time to test it out and tweak I will, but I wanted to give you something to work on.

"(following-sibling::..//h4[@text()='Player Summary'])//table[@class='mod-data']::node()"

The concept here is finding the player summary part that you know is solid and then finding the parent div for that and navigating to the sibling div following the parent and then searching for the table with all the data and pulling out all the nodes that fall under the table structure. You should then be able to cast it to a form that you can parse and loop through to print all the specifics you need out. Play with that and let me know if you get it to work, if not I'll have to find time to execute myself and get the syntax 100%.

  • When i open another url, that particular details showing in different div
    – Ravi
    Commented Apr 4, 2017 at 4:11
  • Can you add the specific html to the question?
    – mutt
    Commented Apr 4, 2017 at 14:09
  • I want to get the text after Player Summary content div. 1. Open the url 2. find Player Summary content 3. That player summary content below we have div. So that div information text need to print. That div is differentiate in multiple urls. I have mentioned two urls. In the 1st url that div is coming as 4th div. In 2nd url that div is coming as 5th div
    – Ravi
    Commented Apr 5, 2017 at 10:54
  • @Ravi Updated answer based on comment...
    – mutt
    Commented Apr 6, 2017 at 14:47

From what I understand, you are trying to get the <h4> tag that points to "Game Information" text. If so, you can write a xpath like shown below :

//h4[text()='Game Information']

If you are searching for any other element, please let me know and I'll be able to help you out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.