晚安,我试图从一个URL下载一个Excel表与请求库,但当我试图保存数据在表格模式,我从URL获得所有信息,但在HTML/文本代码,我不知道如何获得与相关信息的表:
URL = 'https://docs.google.com/spreadsheets/d/1PS2_yAvNVEuSY0gI8Nky73TQMcx_G1i18lm--jOGfAA/edit#gid=514147473'
response = requests.get(URL)
with open('out.csv', 'w', newline='') as f:
writer = csv.writer(f)
for line in response.iter_lines():
writer.writerow(csvheader)
writer.writerow(line.decode('utf-8').split(','))
并获得一些类似于:
<!DOCTYPE html><html lang="en-US"><head><script nonce="JUuaJUl__6QGcoAgULSNpA">var DOCS_timing={}; DOCS_timing[\'pls\']=new Date().getTime();</script><meta property="og:title" content="Datos Argentina - Museos"><meta property="og:type" content="article"><meta property="og:site_name" content="Google Docs"><meta property="og:url" content="https://docs.google.com/spreadsheets/d/1PS2_yAvNVEuSY0gI8Nky73TQMcx_G1i18lm--jOGfAA/edit?usp=embed_facebook"><meta property="og:image" content="https://lh3.googleusercontent.com/N5mR8roa7WP4kn9xvBlt5U-OOKKkSkIGTofqsHXrk2iio25IlUBc-3V9qNJ8sg9Jqptk-mV4H1y7FQ=w1200-h630-p"><meta property="og:image:width"
信息是这样的:dataset from the URL
1条答案
按热度按时间niwlg2el1#
将URL从
/edit
更改为/export?format=csv
:已保存
out.csv
(LibreOffice的屏幕截图):