Beispiel #1
0
 def search(self, item):
     item = quote(item)
     my_url = self.url + "search/?query=" + item
     response = requests.get(
         my_url)  # Opens connection, grabs the webpage and downloads it
     page_html = response.content
     #Parsing html
     page_soup = soup(page_html)
     #grabs each product
     containers = page_soup.findAll(
         "div", {"class": "search-result-gridview-item-wrapper"})
     # print(len(containers))
     storeObj = Store()
     for container in containers:
         out_of_stock = len(containers[0].findAll(
             "div",
             {"class": "product-sub-title-block product-out-of-stock"
              })) != 0
         if not out_of_stock:
             store = Store()
             store.store_name = 'Walmart'
             store.title = container.img["alt"]
             store.image_url = container.img["data-image-src"]
             store.product_url = self.url + container.a["href"]
             store.price = container.findAll(
                 "span", {"class": "visuallyhidden"})[-1].text
             storeObj.add_item(store)
     return storeObj.generate_json()