T
T
ToMyself2022-03-02 13:54:09
Python
ToMyself, 2022-03-02 13:54:09

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: Audit621f4af85fa5e676842301.jpeg 621f4b1660e59465377344.jpeg
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)

What I got (the maximum turned out to display the value as text):
621f4c99508a0359589346.jpeg621f4ca0d9c2e147312246.jpeg621f4ca8917a6706912650.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
demegorych, 2022-03-02
@demegorych

import requests

r = requests.get('https://www.audit-it.ru/buh_otchet/7736050003_pao-gazprom')

print(r.text)

For starters, it's worth looking at what the query actually returns. You should see that the data from the table is filled from the script:
<script>
    var Data = {
    "2011": {
        "date": "31.12.11",
        "period": 2011,
        "values": {
            "1100": "6630253575",
            "1110": "371494",
            "1120": "3079812",
            "1130": "40612661",

Alternatively, parse Data as a dictionary and take data from there.

E
Electro House, 2022-03-04
@laim731

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 question

Ask a Question

731 491 924 answers to any question