나는 Beautiful Soup을 사용하여 간단한 테이블을 긁어 내려고합니다. 나는 그것을 실행할 때마다, 나는이 오류를 얻을, 그러나Beautiful Soup : 'ResultSet'개체에 'find_all'속성이 없습니다?
import requests
from bs4 import BeautifulSoup
url = 'https://gist.githubusercontent.com/anonymous/c8eedd8bf41098a8940b/raw/c7e01a76d753f6e8700b54821e26ee5dde3199ab/gistfile1.txt'
r = requests.get(url)
soup = BeautifulSoup(r.text)
table = soup.find_all(class_='dataframe')
first_name = []
last_name = []
age = []
preTestScore = []
postTestScore = []
for row in table.find_all('tr'):
col = table.find_all('td')
column_1 = col[0].string.strip()
first_name.append(column_1)
column_2 = col[1].string.strip()
last_name.append(column_2)
column_3 = col[2].string.strip()
age.append(column_3)
column_4 = col[3].string.strip()
preTestScore.append(column_4)
column_5 = col[4].string.strip()
postTestScore.append(column_5)
columns = {'first_name': first_name, 'last_name': last_name, 'age': age, 'preTestScore': preTestScore, 'postTestScore': postTestScore}
df = pd.DataFrame(columns)
df
: :이 오류에 대한 다스 StackOverflow의 질문에 주위를 읽고
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-116-a900c2872793> in <module>()
14 postTestScore = []
15
---> 16 for row in table.find_all('tr'):
17 col = table.find_all('td')
18
AttributeError: 'ResultSet' object has no attribute 'find_all'
, 그리고 내가 무엇을 알아낼 수 없습니다 여기 내 코드입니다 잘못하고있다. 이것은 당신에게 결과 집합을 제공
을 사용/이 코드를 실행하여 그 코드를 찾을 수 있습니다 ... –
죄송합니다. 게시물을 수정했습니다. – Anton