[Python] How to read a link from a cell in Google Spreadsheet if it's inside href tag (gspread)

Discussão em 'Python' iniciado por Stack, Março 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am new to stackoverflow, so I sorry in advance if I do something wrong

    I have a spreadsheet on Google sheets, for example, this one

    And there is a link in the cell inside the href tag. I want to get the link and the text of the cell using Google Sheets API or gspread.

    I have already tried this solution but I get access token 'None'.

    I have tried to web scrape with beautifulsoup, but it didn't work as well.

    As for bs4 solution, I tried using this code, that I found here

    from bs4 import BeautifulSoup
    import requests

    html = requests.get('https://docs.google.com/spreadsheets/d/1v8vM7yQ-27SFemt8_3IRiZr-ZauE29edin-azKpigws/edit#gid=0').text
    soup = BeautifulSoup(html, "lxml")
    tables = soup.find_all("table")

    content = []

    for table in tables:
    content.append([[td.text for td in row.find_all("td")] for row in table.find_all("tr")])

    print(content)

    Continue reading...

Compartilhe esta Página