How to retrieve a variable from a website while JavaScript updates it

Viewed 43

I need to save a variable from a website.

On the left there is the website page where the value I need to save (peak_ch1) is indicated, on the right there is the corresponding htlm code.

The variable is defined in Javascript with the following code:

result = ...

$('#peak_ch1').val(result);

With the following Python code:

import requests
from bs4 import BeautifulSoup

url= ...
  
#open with GET method
resp=requests.get(url)
  
#http_respone 200 means OK status
if resp.status_code==200:
    print("Successfully opened the web page")
    print("The news are as follow :-\n")
  
    # we need a parser,Python built-in HTML parser is enough .
    soup=BeautifulSoup(resp.text,'html.parser')    

    # l is the list which contains all the text i.e news 
    l=soup.find("input",{"id":"peak_ch1"})
    print(l)
  
    #now we want to print only the text part of the anchor.
    #find all the elements of a, i.e anchor
    for i in l.findAll("a"):
        print(i.text)
else:
    print("Error")

It prints:

<input class="setfield setfield_info" id="peak_ch1" name="peak_ch1" readonly="" style="margin-top: 5px;" type="text" value="0"/>

But I need the value that is updated by js. How is it possible to retrieve the value?

0 Answers
Related