Python Web Scraping Error

Asked 2 years ago, Updated 2 years ago, 95 views

I have a question regarding Python error.

I'm trying to get data through web scraping, but I made an error when I tried to code it in the way below. What should I do?

I'd appreciate it if you could answer me.


import pandas as pd
import requests
from bs4 import BeautifulSoup
from datetime import datetime
import numpy as np

code = '298000'

fs_rpt_url = "http://comp.fnguide.com/SVO2/ASP/SVD_Finance.asp?pGB=1&gicode=A{}&cID=&MenuYn=Y&ReportGB=&NewMenuID=103&stkGb=701".format(code)
fs_rpt_res = requests.get(fs_rpt_url)
soup = BeautifulSoup(fs_rpt_res.text, "lxml")

data_rows = soup.find("table", attrs = {"class":"us_table_ty1 h_fix zigbg_no"}).find("thead").find_all("tr")

for row in data_rows:
    columns = data_rows.find_all("th")
    row_data = [column.get_text().strip() for column in columns]
    print(row_data)


AttributeError: ResultSet object has no attribute 'find_all'. You're probably treating a list of elements like a single element. Did you call find_all() when you meant to call find()?

python beautifulsoup

2022-09-20 18:01

1 Answers

Try printing except for .find_all("tr"). There is no tr.

data_rows = soup.find("table", attrs = {"class":"us_table_ty1 h_fix zigbg_no"}).find("thead")


2022-09-20 18:01

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.