Парсинг веб-страниц Yahoo FinancePython

Программы на Python
Ответить Пред. темаСлед. тема
Anonymous
 Парсинг веб-страниц Yahoo Finance

Сообщение Anonymous »

Я пытаюсь получить цифры баллов из раздела корпоративного управления по этой ссылке
https://ca.finance.yahoo.com/quote/AMP/profile?p=AMP
Я новичок в Python и не знаю, почему я получаю сообщение об ошибке при удалении веб-страниц.

Код: Выделить всё

import requests
from bs4 import BeautifulSoup

# URL of the webpage to be scraped
url = "https://ca.finance.yahoo.com/quote/AMP/profile?p=AMP"

# Send a GET request to the URL and store the response in a variable
response = requests.get(url)

# Parse the HTML content of the response using BeautifulSoup
soup = BeautifulSoup(response.content, 'html.parser')

# Find the section containing the governance scores
governance_section = soup.find('section', {'class': 'Mt(30px) corporate-governance-container'})

# Find the required elements using their text content and extract their values
scores = governance_section.find('span', text='The pillar scores are')
score_text = scores[0].text.strip() if scores else ''
audit_score = score_text[score_text.find('Audit: ') + 6 : score_text.find(';', score_text.find('Audit: '))].strip()
shareholder_score = score_text[score_text.find('Shareholder Rights: ') + 20 : score_text.find(';', score_text.find('Shareholder Rights: '))].strip()
compensation_score = score_text[score_text.find('Compensation: ') + 14 :].strip()

# Print the extracted information
print("Corporate Governance Score:", governance_section.find('span', {'class': 'Va(m) Fw(600) D(ib) Lh(23px)'}).text.strip())
print("Audit and Risk Oversight Score:", audit_score)
print("Shareholders' Rights Score:", shareholder_score)
print("Compensation Score:", compensation_score)
print("Board Structure Score:", board_score)
Это ошибка

Код: Выделить всё

AttributeError                            Traceback (most recent call last)
 in ()
15
16 # Find the required elements using their text content and extract their values
---> 17 scores = governance_section.find('span', text='The pillar scores are')
18 score_text = scores[0].text.strip() if scores else ''
19 audit_score = score_text[score_text.find('Audit: ') + 6 : score_text.find(';', score_text.find('Audit: '))].strip()

AttributeError: 'NoneType' object has no attribute 'find'
А вот исходный код html

Код: Выделить всё

Minneapolis, Minnesota.Corporate Governance
Ameriprise Financial, Inc.’s ISS Governance QualityScore as of April 1, 2023 is 5.  The pillar scores are Audit: 3; Board: 7; Shareholder Rights: 5; Compensation: 6.
Corporate governance scores courtesy of [url=https://issgovernance.com/quickscore]Institutional Shareholder Services (ISS)[/url].  Scores indicate decile rank relative to index or region. A decile score of 1 indicates lower governance risk, while a 10 indicates higher governance risk.if (window.performance) {window.performance.mark && window.performance.mark('Col1-0-Profile');window.performance.measure && window.performance.measure('Col1-0-ProfileDone','PageStart','Col1-0-Profile');}

Не могли бы вы мне помочь?

Подробнее здесь: https://stackoverflow.com/questions/761 ... oo-finance
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Парсинг веб-страниц / Парсинг веб-страниц Zomato с помощью BeautifulSoup
    Anonymous » » в форуме Python
    0 Ответы
    26 Просмотры
    Последнее сообщение Anonymous
  • Получение новостных статей с веб-сайта Yahoo Finance Canada
    Anonymous » » в форуме Python
    0 Ответы
    21 Просмотры
    Последнее сообщение Anonymous
  • Получение новостных статей с веб-сайта Yahoo Finance Canada
    Anonymous » » в форуме Python
    0 Ответы
    15 Просмотры
    Последнее сообщение Anonymous
  • Получение новостных статей с веб-сайта Yahoo Finance Canada
    Anonymous » » в форуме Python
    0 Ответы
    13 Просмотры
    Последнее сообщение Anonymous
  • Получение новостных статей с веб-сайта Yahoo Finance Canada
    Anonymous » » в форуме Python
    0 Ответы
    23 Просмотры
    Последнее сообщение Anonymous

Вернуться в «Python»