def getlinks(url):
  """Grab HTML from a URL, parse links and add a row per link to spreadsheet."""
  fcols = ['Depth', 'Archive', 'Title', 'Description', 'H1', 'H2', 'ExtractKeywords', 'TopKeyword', 'SERPs', 'Positions', 'Position', 'TopURL']
  therange = 'B1:%s2' % globs.letter[len(fcols)+1]
  CellList = globs.sheet.range(therange)
  vals = fcols + ['0'] + ['?']*(len(fcols)-1)
  for i, val in enumerate(vals):
    CellList[i].value = val
  globs.sheet.update_cells(CellList)
  apexdom = apex(url)
  import lxml.html
  ro = requests.get(url, timeout=5)
  doc = lxml.html.fromstring(ro.text)
  doc.make_links_absolute(url)
  somelinks = doc.xpath('/html/body//a/@href')
  links = set()
  for alink in somelinks:
    if urlparse.urlparse(alink)[1][-len(apexdom):] == apexdom:
      links.add(alink)
  links = list(links)
  y = len(links)
  q = ['?']*y
  linkslist = zip(links,['1']*y,q,q,q,q,q,q,q)
  InsertRows(globs.sheet, linkslist, 2)
  return "0"
dataset/ETHPy150Open miklevin/pipulate/common.py/getlinks/original