[问题] 该如何写入google试算表的指定位置呢?

楼主: kiwigo1000 (快变小黑人了.....)   2023-03-17 15:40:54
我从这个日本旅游网站[步步日本]的首页,抓取了文章的标题与简介的内容,然后使用
pandas来汇整。之后想要将汇整的资料输出到google线上试算表单上面。
https://www.bubu-jp.com/
请问我该如何将pandas的汇整内容,写入试算表单的指定位置呢?
譬如说,不从试算表A1开始写入,而是想从B5这一格开始写入的话,该怎么写呢?
不晓得最后一行的code该如何写才好...
附上code:
import requests
from bs4 import BeautifulSoup
import pandas as pd
import gspread
from google.colab import auth
auth.authenticate_user()
import gspread
from google.auth import default
creds, _ = default()
gc = gspread.authorize(creds)
wb = gc.open_by_key('google试算表的ID')
ws = wb.worksheet('sheet名称')
url = "https://www.bubu-jp.com/"
res = requests.get(url)
soup = BeautifulSoup(res.text, "html.parser")
articles = soup.find_all("div", {"class": "p-blog-archive__item-info"})
result =[]
for article in articles:
title = article.find("h2",{"class":"p-blog-archive__item-title
p-article__title"}).getText()
content = article.find("p",{"class":"p-blog-archive__item-excerpt
u-hidden-xs"}).getText()
result.append([title,content])
df = pd.DataFrame(result, columns=["标题", "简介"])
ws.update([df.columns.values.tolist()] + df.values.tolist())
作者: yiche (你若安好,便是晴天)   2023-03-17 18:17:00
作者: pov (pov)   2023-04-01 14:39:00
pygsheet

Links booklink

Contact Us: admin [ a t ] ucptt.com