【发布时间】:2013-08-09 10:42:34
【问题描述】:
我正在尝试阅读我在 google 文档上的 URL 列表。我想要做的是从谷歌文档电子表格中读取 URL,然后抓取每个 URL。
import gdata.docs.data
import gdata.docs.client
import gdata.docs.service
import gdata.spreadsheet.service
import re, os
username = 'myemail.nuigalway@gmail.com'
password = 'mypassword'
doc_name = 'My document'
gd_client = gdata.spreadsheet.service.SpreadsheetsService()
gd_client.email = username
gd_client.password = password
gd_client.source = 'https://docs.google.com/spreadsheet/ccc? key=0AkGb10ekJtfQdG9EOHN0VzRDdVhWaG1kNVEtdVpyRlE#gid=0'
gd_client.ProgrammaticLogin()
q = gdata.spreadsheet.service.DocumentQuery()
q['title'] = doc_name
q['title-exact'] = 'true'
feed = gd_client.GetSpreadsheetsFeed(query=q)
spreadsheet_id = feed.entry[0].id.text.rsplit('/',1)[1]
feed = gd_client.GetWorksheetsFeed(spreadsheet_id)
worksheet_id = feed.entry[0].id.text.rsplit('/',1)[1]
rows = gd_client.GetListFeed(spreadsheet_id, worksheet_id).entry
for row in rows:
for key in row.custom:
urls = row.custom[key].text
newlist = urls
print 'this is a list', newlist
elec_urls = newlist.strip()
#After this each the Url in the list is scraped using scraperwiki
如果我在电子表格中只有一个 URL,这可以正常工作,但我没有,当我在文档中有多个 URL 时,程序只会抓取最后一个 URL。
我认为使用循环可以解决从 newlist[0] 到 newlist[i] 循环的问题,但发现 newlist[0] = to h of the h t t p://(URL) Last enters urls and newlist [1]= t 等等。
任何帮助将不胜感激。
【问题讨论】:
标签: python google-docs-api google-spreadsheet-api