In [1]:
import requests, json, re
from BeautifulSoup import *
from pprint import pprint
In [2]:
url = "https://www.giftcardmall.am/en/"
response = requests.get(url)
page_0 = response.text
soup_0 = BeautifulSoup(page_0)
In [3]:
new_url = soup_0.find('a', attrs={'class':"btn-u btn-orange browse-all-btn"}).get('href')
response = requests.get(new_url[1:-1])
page = response.text
soup = BeautifulSoup(page)
In [6]:
divisions = soup.findAll('div',attrs={'class':'card_animate card all_cards col-lg-3 col-md-4 col-xs-6'})
my_dict = {}
for div in divisions:
card_link = div.find('a').get('href')
card_name = re.findall('gift-card/(.+)',card_link)
for_card_price = div.find('p').text.encode('utf-8')
if "-" in for_card_price:
card_price_1 = re.findall('^(\d+).+',for_card_price)[0]
card_price_2 = re.findall('- (\d+).+$',for_card_price)[0]
card_price = str(0.5*(float(card_price_1)+float(card_price_2)))
else:
card_price = re.findall('(\d+).+',for_card_price)[0]
card_dict = {"link":card_link,"price":card_price}
my_dict.update({card_name[0]:card_dict})
pprint(my_dict)
In [7]:
with open("giftcards.json",'w') as f:
json.dump(my_dict,f,indent=4)