我遇到了这个错误(attributeerror:'bytes'对象没有属性'read')这个程序从这个站点收集信息

vaj7vani  于 2021-09-08  发布在  Java
关注(0)|答案(1)|浏览(655)
import json
from urllib.request import urlopen

with urlopen("https://sis.ou.edu/ted/home/byOther?stat_code=ID&sbgi_code=004114&trns_subj_code=&trns_subj_crse=") as response:
   source=response.read()

data= json.load(source)

print(json.dumps(data, indent=2))
ddhy6vgd

ddhy6vgd1#

要从字符串解析json,请使用 json.loads (注意 s 最后)。但是从 urlopen 不是json格式(它是html页面)。要解析它,可以使用 pandas.read_html :

import pandas as pd

url = "https://sis.ou.edu/ted/home/byOther?stat_code=ID&sbgi_code=004114&trns_subj_code=&trns_subj_crse="
df = pd.read_html(url)[0]
print(df)

印刷品:

TransferSubject TransferCourse                  Transfer Title    TransferHours          TransferLevel Connector OU Subject  OU Course                        OU Title  OUCredits                       Gen. Ed.  Pass
0              ACCB            129     INTRODUCTION TO BOOKKEEPING                5         LOWER DIVISION       NaN        TRF       1999  LOWER DIVISION TRANSFER CREDIT          5                            NaN   NaN
1              ACCB            229       QUICKBOOKS PRO ACCOUNTING                5         LOWER DIVISION       NaN        TRF       1999  LOWER DIVISION TRANSFER CREDIT          5                            NaN   NaN
2              ACCT            201              PRIN OF ACCOUNTING                4  Lower Division Course       NaN       ACCT       2113   FUNDMNTL FINANCIAL ACCOUNTING          3                            NaN   NaN
3              ACCT            201              PRIN OF ACCOUNTING                4  Lower Division Course       AND       ACCT       1999  LOWER DIVISION TRANSFER CREDIT          1                            NaN   NaN
4              ACCT            202                PRINC OF ACCT II                4  Lower Division Course       NaN       ACCT       2123  FUNDMNTL MANAGERIAL ACCOUNTING          3                            NaN   NaN
5              ACCT            202                PRINC OF ACCT II                

...and so on.

相关问题