簡體   English   中英

為什么我可以訪問包含公共文件的https網頁,卻不能使用Python腳本下載它們?

[英]Why is that I can visit https webpage containing public files but I can't download them using Python script?

我的用戶名和密碼應該是什么?

import requests
import shutil

url = "https://www.sec.gov/Archives/edgar/daily-index/2017/QTR1/company.20170111.idx.txt"    

#Note: It's https

r = requests.get(url, auth=('', ''), verify=False,stream=True)

r.raw.decode_content = True

with open("company.20170111.idx.txt", 'wb') as f:
    shutil.copyfileobj(r.raw, f) 

您要加載的網址應為:

https://www.sec.gov/Archives/edgar/daily-index/2017/QTR1/company.20170103.idx

您還缺少import requests ,並且服務器端不喜歡auth參數。

import shutil
import requests

url = "https://www.sec.gov/Archives/edgar/daily-index/2017/QTR1/company.20170111.idx"

r = requests.get(url, verify=False, stream=True)

r.raw.decode_content = True

with open("company.20170111.idx.txt", 'wb') as f:
    shutil.copyfileobj(r.raw, f)

這很好。 我不知道為什么:

import urllib2
url = "https://www.sec.gov/Archives/edgar/daily-index/2017/QTR1/company.20170111.idx"
r = urllib2.urlopen(url)
for l in r:
    print l

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM