0

Given the following code:

import requests

url = "https://signal.bz/"
response = requests.get(url)
print(response.text)

The output is JS code.

But what I want to get is the HTML code I see when I open my browser's Developer Tools at https://signal.bz/.

For other sites, I get HTML code well, but why is this site only getting JS code?
How can I get HTML code for this site?

1
  • 2
    When you open DevTools, what you see is the rendered HTML, not necessarily the HTML sent by the server. In this case, it seems the website sends JS that generates the DOM (rendered HTML) that you see. requests does not execute JS, so it can't possibly have that. Consider using a headless browser like Puppeteer for that. Commented May 1, 2022 at 13:25

1 Answer 1

1

What you get is html code. Look at the start of the file <!DOCTYPE html><html lang=en>

The javascript code is a script which is part of the html document and is supposed to create the content when the document is rendered by the web browser.

To see the content you can install and use the library requests-html instead of requests

To render the html use response.render() and then you can get the content as usually with response.text

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.