Skip to content

Instantly share code, notes, and snippets.

@kellylawrence
Created January 25, 2021 20:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kellylawrence/616bf847bacfcfa9974d19b42065d05a to your computer and use it in GitHub Desktop.
Save kellylawrence/616bf847bacfcfa9974d19b42065d05a to your computer and use it in GitHub Desktop.
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