Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- import bs4, requests, sys, os
- from jinja2 import Template
- searchURL = 'https://www.ebay-kleinanzeigen.de/s-10587/leuchte/k0l3346r10'
- def getEbayListing(searchURL): # grab Listings
- res = requests.get(searchURL) # get html
- res.raise_for_status() # check if error
- soup = bs4.BeautifulSoup(res.text, "html.parser") # parse html
- productDIVs = soup.select("div.aditem-image > div") # grab DIV
- productDict = {} # create dict to store ouput
- for product in productDIVs:
- productURL = "https://www.ebay-kleinanzeigen.de" + product.get('data-href') # grab URL
- largeImage = product.get('data-imgsrc').strip("$_9.JPG") + "$_32.JPG" # grab ImageLink
- productDict[productURL] = largeImage # Populate List
- return productDict
- def createHTML(productDict):
- htmltext = Template('''<link rel="stylesheet" href="styles.css">
- <html>
- <head>
- <h1>Images for Search</h1>
- </head>
- <body
- <div class="gallery">
- <div>
- {% for url, image in productDict.items() %}
- <a href="{{ url }}"><img src="{{ image }}" width="300" height="500"/></a>
- {% endfor %}
- </div>
- </div>
- </body>
- </html>''')
- return htmlText
- sys.argv # get args
- if len(sys.argv) > 1: # check args
- searchURL = ' '.join(sys.argv[1:])
- productDict = getEbayListing(searchURL)
- htmlText = createHTML(productDict)
- htmlText.stream(productDict = productDict).dump('test.html')
- print('File successfully written to: ' + os.getcwd())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement