Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Python Web Scraping Script (Online Store Stock Check)
# Imports
from bs4 import BeautifulSoup
import requests
# Target URL's
targetURLs = [
'https://www.rightstufanime.com/Lupin-the-3rd-Blood-Seal-of-the-Eternal-Mermaid-Blu-ray',
'https://www.rightstufanime.com/Lupin-the-3rd-Goemons-Blood-Spray-Blu-ray',
'https://www.rightstufanime.com/Lupin-the-3rd-Jigens-Gravestone-Blu-ray'
]
targetStockStatus = []
for targetURL in targetURLs:
# Variables
request = requests.get(targetURL)
result = BeautifulSoup(request.text,'lxml')
serverStatus = request.status_code
# If page is available
if serverStatus == 200:
# If item is in stock
stockStatus = result.find('', "product-line-stock-msg-in")
if stockStatus:
print "In stock! | " + targetURL
targetStockStatus.append("y")
else:
print "Not in stock. :( | " + targetURL
targetStockStatus.append("n")
else:
print "Can't parse the target URL. :("
print targetStockStatus
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment