Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import sys
- from urllib.request import urlopen, Request
- from bs4 import BeautifulSoup
- titulo, plataforma, soporte, anio = range(4)
- def get_year(titulo, plataforma):
- url = "https://www.google.com/search?q=" + titulo.replace(" ", "+") + "+" + plataforma + "+year"
- page = urlopen(Request(url, headers={"User-Agent": "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:69.0) Gecko/20100101 Firefox/69.0"})).read()
- soup = BeautifulSoup(page, "html.parser")
- year = soup.find_all("div", class_=["Z0LcW"])[0].contents[0][-4:]
- return year
- csv_reader = csv.reader(sys.stdin)
- csv_writer = csv.writer(sys.stdout)
- for game in csv_reader:
- if not game[anio]:
- title = game[titulo]
- platform = game[plataforma]
- try:
- new_year = get_year(title, platform)
- except:
- new_year = ""
- game[anio] = new_year
- csv_writer.writerow(game)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement