Created
January 25, 2021 20:12
-
-
Save kellylawrence/616bf847bacfcfa9974d19b42065d05a to your computer and use it in GitHub Desktop.
Python Web Scraping Script (Online Store Stock Check)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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