我想将此文件下载到我的本地驱动器: https ://www.sec.gov/Archives/edgar/data/1556179/0001104659-20-000861.txt
这是我的代码:
import requests
import urllib
from bs4 import BeautifulSoup
import re
path=r"https://www.sec.gov/Archives/edgar/data/1556179/0001104659-20-000861.txt"
r=requests.get(path, headers={"User-Agent": "b2g"})
content=r.content.decode('utf8')
soup=BeautifulSoup(content, "html5lib")
soup=str(soup)
lines=soup.split("\\n")
dest_url=r"C://Users/YL/Downloads/a.txt"
fx=open(dest_url,'w')
for line in lines:
fx.write(line + '\n')
那我应该怎么下载文件呢?非常感谢!