相关疑难解决方法(0)

美丽的汤:'ResultSet'对象没有属性'find_all'?

我正在尝试使用Beautiful Soup刮一张简单的桌子.这是我的代码:

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
Run Code Online (Sandbox Code Playgroud)

但是,每当我运行它时,我都会收到此错误:

--------------------------------------------------------------------------- …
Run Code Online (Sandbox Code Playgroud)

python beautifulsoup

29
推荐指数
2
解决办法
6万
查看次数

标签 统计

beautifulsoup ×1

python ×1