-1

When I right-click part of a webpage in Chrome and select "Inspect," I get the text I need under the "Elements" tab of the "Developer tools" (accessed through F12).

How can I get that same text with Python please? (I'm very new to Python but not new to programming.) Thanks in advance!

I've tried viewing the webpage's source code but it doesn't contain the same text as when I use right-click, "Inspect," I've been searching Google for solutions. I've read about Selenium, BS4, but I don't understand how these libraries (?) would acquire that desired text. I've installed Visual Studio Code.

1 Answers1

-1

Please use pyscript.

<html>

<head>
  <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
  <script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<div id="div">foo</div>
<py-script>
  import js

  div = js.document.getElementById("div")
  print(div.innerText)
</py-script>
</body>

</html>
Norio Yamamoto
  • 1,495
  • 2
  • 3
  • 10
  • 1
    Thanks. I don't understand how PyScript is applicable here. When I view the webpage's source code it doesn't contain the same text as when I use right-click, "Inspect," (in Chrome) on the webpage. Do I need to view the source code, add the code above, save the code as an HTML, and then load the HTML file in my browser? Thanks! – Noam Chomsky May 21 '23 at 21:08
  • Please read this. https://pyscript.net/ – Norio Yamamoto May 21 '23 at 21:35