Created
September 5, 2018 21:50
-
-
Save kirussian911/a6b29e55572222c5d067fef669c96efb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from bs4 import BeautifulSoup | |
import csv | |
import urllib.request | |
url = 'https://aliholic.com/shop/' | |
def get_html(url): | |
response = urllib.request.urlopen(url) | |
return response.read() | |
def get_data(html): | |
soup = BeautifulSoup(html, 'lxml') | |
table = soup.find('div', {'class': 'blog-grid-wrap'}) | |
projects = [] | |
for row in table.find_all('article'): | |
cols = row.find_all('div', {'class': 'hentry-middle'}) | |
projects.append({'title': cols[0].a.text, | |
'old_price':[old_price.text for old_price in cols[0].div.find_all('del')], | |
'price':[price.text for price in cols[0].div.find_all('ins')]}) | |
return projects | |
def main(): | |
print(get_data(get_html(url))) | |
if __name__=="__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment