A
A
alex-bul2020-06-23 05:35:42
Python
alex-bul, 2020-06-23 05:35:42

How to edit website code with python?

Hello. there is a need to change the data on the site for the screenshot. I want to try to do it by editing the element code on the page. Can you suggest libraries or other ways to implement this.

It is necessary: ​​the script opens the site with some data, and at the output it gives a screen with other numerical data, which are generated according to special settings.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Kuts, 2020-06-23
@KOT10

Easy to do with Selenium:

driver.get('http://lenta.ru')
driver.execute_script('''
var aTags = document.getElementsByTagName("a");
for (var i = 0; i < aTags.length; i++) {
  if (aTags[i].innerText.startsWith("07:50Опубликованы данные")) {
    aTags[i].innerText = "Утки с Марса захватили вселенную!";
    break;
  }
}
''')
time.sleep(1)

screenshot = driver.get_screenshot_as_png()

I took a more complicated example. In your case, for sure, the selector can be chosen simpler
5ef193d5d223f668104370.png

H
HemulGM, 2020-06-23
@HemulGM

You use some framework so that you can add a browser host to the window. For example Qt.
You load the page into the browser and change it, either by accessing the DOM or by executing scripts. QtWebEngine allows this. Then you take a picture.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question