通过 Python 下载 JSON 文件
Downloading JSON file through Python
我有一个 link,每次我 运行 它都会给我一个 .pst 文件的 "save as" 对话框。
我想尝试将文件保存到 'sample.txt' 文件而不打开它,因为大小是 500 MB。
有什么办法可以解决这个问题..?
import urllib
jsonl = urllib.request.urlopen("test.com/csv?date=2019-07-17")
我试过上面的代码,但它给了我
<http.client.HTTPResponse at 0x9ac4k10>
您需要从 urlopen returns 的对象中读取数据。
尝试
import urllib
with urllib.request.urlopen("test.com/csv?date=2019-07-17") as f:
jsonl = f.read()
好的,我在与网站交互时遇到了很多麻烦。我决定只使用网络浏览器库。
import webbrowser
chrome_path="C:xxx\Google\Chrome\Application\chrome.exe"
webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(chrome_path))
url = 'http://testsite/csv?date=2019-07-18'
设置 chrome 自动下载文件会填充我的下载文件夹,我可以从那里自动执行其他所有操作:)
我有一个 link,每次我 运行 它都会给我一个 .pst 文件的 "save as" 对话框。 我想尝试将文件保存到 'sample.txt' 文件而不打开它,因为大小是 500 MB。
有什么办法可以解决这个问题..?
import urllib
jsonl = urllib.request.urlopen("test.com/csv?date=2019-07-17")
我试过上面的代码,但它给了我
<http.client.HTTPResponse at 0x9ac4k10>
您需要从 urlopen returns 的对象中读取数据。
尝试
import urllib
with urllib.request.urlopen("test.com/csv?date=2019-07-17") as f:
jsonl = f.read()
好的,我在与网站交互时遇到了很多麻烦。我决定只使用网络浏览器库。
import webbrowser
chrome_path="C:xxx\Google\Chrome\Application\chrome.exe"
webbrowser.register('chrome', None,webbrowser.BackgroundBrowser(chrome_path))
url = 'http://testsite/csv?date=2019-07-18'
设置 chrome 自动下载文件会填充我的下载文件夹,我可以从那里自动执行其他所有操作:)