0

How to extract all the ratings(numbers) with XPath from the following page? Thank you. Top 50 best films of 2018

1 Answers1

1

If to find only by class of <span> that contains rating, then you will get a lot of other items. So I selected the parent <div> by class and then got the <span> by class. It seems to work fine.

//div[@class="ipl-rating-star small"]/span[@class="ipl-rating-star__rating"]/text()

Useful info:

qwermike
  • 1,201
  • 2
  • 9
  • 22
  • Thank you. May I ask the technique to find that? – wishmaster75 Feb 13 '19 at 18:19
  • 1
    Well, I [use Chrome Developer Tools](https://stackoverflow.com/a/22573161/7128891). I inspected the rating element, so I got it in Elements Tab. First thing I tried - was to find by class of the found ``. But it didn't work. So I used parent element, as described in answer, and it worked. – qwermike Feb 13 '19 at 18:25
  • May I also ask where and how do you check the results? – wishmaster75 Feb 13 '19 at 18:38
  • 1
    If you open Chrome DevTools > Elements tab, press Ctrl+F and paste XPath from answer, it will highlight 100 elements(ratings) in the HTML (because there are 100 movies on the page). – qwermike Feb 13 '19 at 18:44
  • Also you can use Javascript in Console tab. Just execute `$x('//div[@class="ipl-rating-star small"]/span[@class="ipl-rating-star__rating"]/text()').map(x => x.data)` and you will get the array or ratings. – qwermike Feb 13 '19 at 18:45
  • You helped a lot. Will try it tomorrow, now I don’t have access to my computer. – wishmaster75 Feb 13 '19 at 18:54
  • Is it possoble to export the mapping from console? – wishmaster75 Feb 13 '19 at 20:05
  • You can do whatever you want with Javascript. If you need more answers - better ask new question and include more details and tools you use. – qwermike Feb 13 '19 at 22:20