【发布时间】:2022-02-15 00:17:23
【问题描述】:
我的问题可能已经问过,但我为我工作的场景没有得到任何帮助。
尝试了不同的方法和事情,但仍然没有运气,任何帮助将不胜感激
问题
我正在尝试从 URL https://www.sec.gov/Archives/edgar/cik-lookup-data.txt 加载文本文件,因此我可以修改数据并创建数据框。
示例:- 来自链接的数据
1188 百老汇有限责任公司:0001372374:
119 博伊西有限责任公司:0001633290:
11900 东阿蒂西亚大道有限责任公司:0001639215:
11900 哈兰路有限责任公司:0001398414:
11:11 资本公司:0001463262:
我应该得到低于输出
Name | number
1188 BROADWAY LLC | 0001372374
119 BOISE, LLC | 0001633290
11900 EAST ARTESIA BOULEVARD, LLC | 0001639215
11900 HARLAN ROAD LLC | 0001398414
11:11 CAPITAL CORP. | 0001463262
我遇到了加载文本文件的第一个问题,我不断收到 403 url HTTPError: HTTP Error 403: Forbidden
参考文献:
- Given a URL to a text file, what is the simplest way to read the contents of the text file?
- Python requests. 403 Forbidden
我的代码:-
import urllib.request # the lib that handles the url stuff
data = urllib.request.urlopen("https://www.sec.gov/Archives/edgar/cik-lookup-data.txt") # it's a file like object and works just like a file
for line in data: # files are iterable
print (line)
【问题讨论】:
-
有意思,不知道是不是和用户代理有关?编辑:nvm,这在你的链接中,也许是类似的东西?