简体   繁体   English

我收到这个错误(AttributeError: 'bytes' object has no attribute 'read')这个程序从这个站点收集信息

[英]I got this error(AttributeError: 'bytes' object has no attribute 'read') This program collects information from this site

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))

To parse Json from string use json.loads (note the s at the end).要从字符串解析 Json,请使用json.loads (注意末尾的s )。 But the data received from urlopen is not in Json format (it's HTML page).但是从urlopen接收到的数据不是 Json 格式的(它是 HTML 页面)。 To parse it, you can use for example pandas.read_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)

Prints:印刷:

    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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python; urllib 错误:AttributeError: 'bytes' object 没有属性 'read' - Python; urllib error: AttributeError: 'bytes' object has no attribute 'read' AttributeError: 'bytes' object 没有属性 'read' - AttributeError: 'bytes' object has no attribute 'read' 我收到此错误 AttributeError: 'function' object has no attribute 'hlauncher' while试图从另一个文件中获取属性 - I got this error AttributeError: 'function' object has no attribute 'hlauncher' while trying to get a attribute from another file AttributeError: 'bytes' object 在 Python Sockets 库上没有属性 'read' - AttributeError: 'bytes' object has no attribute 'read' on Python Sockets Library AttributeError: 'bytes' object 从 python 中的 GCS 读取.gz 文件时没有属性 'read' - AttributeError: 'bytes' object has no attribute 'read' while reading .gz file from GCS in python 错误 python 代码:AttributeError: 'bytes' object 没有属性 'encode' - error python code: AttributeError: 'bytes' object has no attribute 'encode' .wav 文件错误:“AttributeError: 'bytes' object has no attribute 'seek'” in python - .wav file error : “AttributeError: 'bytes' object has no attribute 'seek'” in python 如何修复 AttributeError: 'bytes' object has no attribute 'encode'? - How do I fix AttributeError: 'bytes' object has no attribute 'encode'? 我得到了这个AttributeError:'module'对象没有属性'QuerySet' - i got this AttributeError: 'module' object has no attribute 'QuerySet' 在设置视图集时,出现错误 AttributeError: 'function' object has no attribute 'get_extra_actions' - In setting viewset, I got an error AttributeError: 'function' object has no attribute 'get_extra_actions'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM