-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomasg.py
More file actions
44 lines (34 loc) · 875 Bytes
/
comasg.py
File metadata and controls
44 lines (34 loc) · 875 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import csv
import requests
from bs4 import BeautifulSoup
import json
file = open('Amazon Scraping - Sheet1.csv')
csvreader = csv.reader(file)
header = []
header = next(csvreader)
print(header)
row = []
nos =0
jdata={}
for row in csvreader:
country = row[3]
asin = row[2]
url = "https://www.amazon."+str(country)+"/dp/"+str(asin)
req = requests.get(url)
htmlcontent = req.content
soup = BeautifulSoup(htmlcontent, 'html.parser')
title = soup.title.get_text()
print(url+" done!")
img = soup.find_all('img')
desc = soup.find_all('p')
nos +=1
jdata ={
""+str(nos)+"":{
"url":""+str(url)+"",
"title":""+str(title)+"",
"image":""+str(img)+"",
"description":""+str(desc)+""
}
}
with open('data.json', 'a') as outfile:
json.dump(jdata, outfile)