0

I am new to web development, and I only know basics in HTML. I would like to retrieve from one web page one element, to put it on my web page, so it can change interactively.

Is it possible with HTML?

As an example, let’s say I want to retrieve the general rating of this movie (7.7) from this webpage https://www.senscritique.com/serie/Big_Little_Lies/21097041

I understood I might need to use PHP or JS, and I am also not sure about how to identify the name of the element I want to pull. I saw the class="pvi-scrating-value" but I’m not sure how to go from there

Progress on answer:

<!DOCTYPE html>
<html>
<body>

<div>Expected value: <b>7.7</b></div>
<div>Actual value: <b id="ret"></b></div>
<script>
  var getElementByXPath = function(a,b){b=document;return b.evaluate(a,b,null,9,null).singleNodeValue}
  var path = '//html/body/div[3]/section/div/div/div/div[3]/span';
  document.getElementById('ret').innerHTML = getElementByXPath(path).innerHTML;
</script>

</body>
</html>

Any help is most welcome :)

Laketi
  • 1
  • 3

1 Answers1

0

I think you can fetch using the XPath of that particular element. Which in you case is /html/body/div[3]/section/div/div/div/div[3]/span

To find xPath of any element you can right click > inspect > Right click on that element code > Copy > Copy XPath

Exact solution is given here Is there a way to get element by XPath using JavaScript in Selenium WebDriver?

Umair Mohammad
  • 4,489
  • 2
  • 20
  • 34
  • thank you for the quick reply! i should end of with the below HTML code, i replaced the path with the XPath, however the return value is empty, Am i doing something wrong?
    Expected value: 7.7
    Actual value:
    – Laketi Nov 22 '17 at 14:53