python 웹스크래핑 오류
조회수 2103회
파이썬 오류 관련 질문드립니다.
웹스크래핑으로 데이터를 가져오려는데, 아래의 방식으로 코드를 짰더니 오류가 납니다. 어떻게 해야 할까요?
답변주시면 감사하겠습니다.
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()?
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
.find_all("tr")을 제외하고 출력해보세요. tr이 없습니다.
data_rows = soup.find("table", attrs = {"class":"us_table_ty1 h_fix zigbg_no"}).find("thead")
댓글 입력