织梦CMS - 轻松建站从此开始!

欧博ABG官网-欧博官方网址-会员登入

How to get a table from google docs using a URL in

时间:2025-08-24 20:32来源: 作者:admin 点击: 1 次
I solved this - since it's for a job application I'm not going to provide the full solution but I can point you in the right direction. I don't think

I solved this - since it's for a job application I'm not going to provide the full solution but I can point you in the right direction. I don't think you need to complicate things with Google Docs APIs - if you look at the response from the url, you'll notice that the data you want is in a table tag and that there is only one table element in the document. You can use an HTML parser to fetch this data pretty easily. Suggest you look at html.parser

For me steps were:

Create a parser that finds the table data you want and extracts the values from each row (start by just printing them to the console). You'll need to have a way to track when you hit a start tag for a table and also an end tag for a table. Also account for the fact that the first row has no data (column headers)

Create some data object that will be populated by the parser - I used a List of List objects. You'll want to call a method that updates this after reading a row of data from the table (every 3 values). You'll also need to handle padding - if you get a value that "skips" columns or lines, the skipped lines should be padded with empty lines and the skipped columns should be padded with spaces.

You'll need a method to print this data object. Note that the (0,0) value is in the bottom left of the image

This should be enough to get you started:

import requests from html.parser import HTMLParser class GoogleDocDecoderHTMLParser(HTMLParser): inTable = False def handle_starttag(self, tag, attrs): if tag == "table": self.inTable = True def handle_endtag(self, tag): if tag == "table": self.inTable = False def handle_data(self, data): if self.inTable: print(data) class GoogleDocDecoder: URL = "https://docs.google.com/document/d/e/2PACX-1vQGUck9HIFCyezsrBSnmENk5ieJuYwpt7YHYEzeNJkIb9OSDdx-ov2nRNReKQyey-cwJOoEKUhLmN9z/pub" def decodeFromUrl(url): response = requests.get(url) html_content = response.content parser = GoogleDocDecoderHTMLParser() parser.feed(response.text) decodeFromUrl(URL)

(责任编辑:)
------分隔线----------------------------
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
评价:
表情:
用户名: 验证码:
发布者资料
查看详细资料 发送留言 加为好友 用户等级: 注册时间:2025-08-25 11:08 最后登录:2025-08-25 11:08
栏目列表
推荐内容