I have a db.sql file that includes lots of urls like as follows.
....<td class=\"column-1\"><a href=\"http://geni.us/4Lk5\" rel=nofollow\"><img src=\"http://www.toprateten.com/wp-content/uploads/2016/08/25460A-Panini-Press-Gourmet-Sandwich-Maker.jpg \" alt=\"25460A Panini Press Gourmet Sandwich Maker\" height=\"100\" width=\"100\"></a></td><td class=\"column-2\"><a href=\"http://geni.us/4Lk5\" rel=\"nofollow\">25460A Panini Press Gourmet Sandwich Maker</a></td><td class....
As you can see, there is http://geni.us/4Lk5\ in the file.
I have another product.csv files that contains ID (like 4LK5 above) and Amazon product URL like as follows.
4Lk5 8738 8/16/2016 0:20 https://www.amazon.com/gp/product/B00IWOJRSM/ref=as_li_qf_sp_asin_il_tl?ie=UTF8
Jx9Aj2 8738 8/22/2016 20:16 https://www.amazon.com/gp/product/B007EUSL5U/ref=as_li_qf_sp_asin_il_tl?ie=UTF8
9sl2 8738 8/22/2016 20:18 https://www.amazon.com/gp/product/B00C3GQGVG/ref=as_li_qf_sp_asin_il_tl?ie=UTF8
As you can see, there is 4LK5 which matches with Amazon product URL.
I have already read the csv file and pick only ID and Amazon product url with python.
def openFile(filename, mode):
index = 0
result = []
with open(filename, mode) as csvfile:
spamreader = csv.reader(csvfile, delimiter = ',', quotechar = '\n')
for row in spamreader:
result.append({
"genu_id": row[0],
"amazon_url": row[3]
});
return result
I have to add some code to search appropriate URL with genu_id in the db.sql and replace with amazon_url described on the code above.
Please help me.
lxml.htmlor similar?