Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- soup = BeautifulSoup(response.content, "lxml")
- product_size = []
- try:
- if "Add to Cart" in response.text:
- for y in soup.find_all("script", {"type": "text/javascript"}):
- if "spConfig =" in y.text:
- regex = re.compile(r'var spConfig = new Product.Config\((.*?)\);')
- match = regex.search(y.text)
- spConfig = json.loads(match.groups()[0])
- for key in spConfig['attributes']: # Should only call once
- for product in spConfig['attributes'][key]['options']:
- product_size.append(product['label_uk'])
- except:
- pass
- if len(product_size) == 0:
- product_size = "No Stock"
- try:
- product_price = soup.find('span', {'class': 'price'}).text
- except:
- product_price = "Null"
- try:
- product_name = soup.find('meta', {'property': 'og:title'})["content"]
- except:
- product_name = product_link
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement