python - Comparing keywords in a page or CSV file: PHP ? Bash? -
i have series of keywords in html web page - comma separated them csv, , know ones notin csv file displayed html web page. how comparison ? have ideas mysql , tables csv or html sources. !
in python, given 2 csv files, a.csv , b.csv, script create (or edit if exists) new file out.csv contains in a.csv that's not found in b.csv.
import urllib url = 'http://www.website.com/x.csv' urllib.urlretrieve(url, 'b.csv') file_a = open('a.csv', 'r') file_b = open('b.csv', 'r') file_out = open('out.csv', 'w') list_a = [x.strip() x in file_a.read().split(',')] list_b = [x.strip() x in file_b.read().split(',')] list_out = list(set(list_a) - set(list_b)) # reverse if necessary file_out.write(','.join(list_out)) file_out.close()
Comments
Post a Comment