Answer the question
In order to leave comments, you need to log in
How to parse these values and write them to variables?
Good afternoon, please tell me how to parse these values and write them to variables.
I take the values from the site: Audit
Tried in different ways, but nothing happened in 4 days (I just started to study this)
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
import os
import time
target_page = "https://www.audit-it.ru/buh_otchet/7736050003_pao-gazprom"
xpath_testing = '//*[@id="tblIdx1"]/tbody/tr[4]/td[3]'
dir_current = os.getcwd()
driverLocation = dir_current + "\chromedriver.exe"
chrome_options = Options()
chrome_options.add_argument("--headless")
driver = Chrome(driverLocation, chrome_options=chrome_options)
data_text = driver.get(target_page)
elements = driver.find_elements(By.XPATH, xpath_testing)
print(elements)
import requests
from lxml import html
pageContent=requests.get('https://www.audit-it.ru/buh_otchet/7736050003_pao-gazprom')
tree = html.fromstring(pageContent.content)
g=tree.xpath('//*[@id="octable"]/tr/td[8]/b/text()')
print(g)
Answer the question
In order to leave comments, you need to log in
import requests
r = requests.get('https://www.audit-it.ru/buh_otchet/7736050003_pao-gazprom')
print(r.text)
<script>
var Data = {
"2011": {
"date": "31.12.11",
"period": 2011,
"values": {
"1100": "6630253575",
"1110": "371494",
"1120": "3079812",
"1130": "40612661",
Selenium is not needed here.
requests bs4 for starters, that's it. Lots of manuals.
You can easily collect data. You don't need to write to variables! Write a lot of data in a dictionary. Then you can do whatever you want with them, even wrap them in json.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question