Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. import csv
  2. import sys
  3. from urllib.request import urlopen, Request
  4. from bs4 import BeautifulSoup
  5.  
  6. titulo, plataforma, soporte, anio = range(4)
  7. def get_year(titulo, plataforma):
  8.     url = "https://www.google.com/search?q=" + titulo.replace(" ", "+") + "+" + plataforma + "+year"
  9.     page = urlopen(Request(url, headers={"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0"})).read()
  10.     soup = BeautifulSoup(page, "html.parser")
  11.     year = soup.find_all("div", class_=["Z0LcW"])[0].contents[0][-4:]
  12.     return year
  13.  
  14. csv_reader = csv.reader(sys.stdin)
  15. csv_writer = csv.writer(sys.stdout)
  16. for game in csv_reader:
  17.     if not game[anio]:
  18.         title = game[titulo]
  19.         platform = game[plataforma]
  20.         try:
  21.             new_year = get_year(title, platform)
  22.         except:
  23.             new_year = ""
  24.         game[anio] = new_year
  25.     csv_writer.writerow(game)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement