Итак, я пытался создать базовый c веб-скребок, и я смотрю, смогу ли я при поиске в Google go получить результат, который не первый. Я пишу на лист Excel и использую функцию .nrows, чтобы получить количество элементов, а затем я хотел бы получить результат поиска .nrows + 1 и далее. Вот мой код:
import xlrd
from googlesearch import search
from pip._vendor.distlib.compat import raw_input
from xlwt import Workbook
import os
def get_n_add_links(query, cur_spot):
counter = cur_spot
for i in search(query, tld='com', lang='en', num=10, start=cur_spot, stop=None, pause=2.0):
print(i)
scraper_doc.write(counter, 0, i)
counter += 1
queryData.save(query + 'link.xls')
# Creates an .xls file and a sheet within that file
queryData = Workbook()
scraper_doc = queryData.add_sheet('Links')
query = raw_input('What would you like to scrape today? ')
file_path = os.path.join('/Users/vasilypiccone/scraperMKI', query)
if os.path.isfile(file_path):
full_path = os.path.join('/Users/vasilypiccone/scraperMKI', file_path)
# check num_rows and then count to that link in the google API
# then, add the n + 1 to the m th link to the sheet
# (possibly do it multiple times)
doc = xlrd.open_workbook(full_path)
sheet = doc.sheet_by_index(0)
print(sheet.nrows)
get_n_add_links(query, sheet.nrows)
else:
get_n_add_links(query, 0)