Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
417 views
in Technique[技术] by (71.8m points)

python - I have managed to get data writing into Google Sheets but I would like to be able to 'overwrite' the data rather than 'insert_row'

The error I get when I try and do 'update_row' is the following:

AttributeError: 'Worksheet' object has no attribute 'update_row'

Here is my code:

listing = soup.find_all('div', 'result-contain')
for details in listing:
title = details.find('h3')
if not title:
    continue
title = title.text.strip()[0:28]
price = details.find('div', 'price')
mileage = details.find_all('li')[0]
just_miles = mileage.text.split()
miles = just_miles[:-1]
adjusted_miles = str(miles)[1:-1]
adjusted_miles = adjusted_miles.replace("'", "")
link = details.find('a')

print(title, price.text, adjusted_miles, link['href'])
index = 2
row = [title,price.text,adjusted_miles,link['href']]
sheet1.insert_row(row,index)

Amy ideas please?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

gspread has no update_row method, you must be looking for worksheet.update() method.

Tip: You could use python's dir() method to view all properties and methods of the specified object.

This example is from gspread worksheet object:

enter image description here

Reference:

gspread Documentation


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...