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'
Код: Выделить всё
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