-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPUWebScraper.py
More file actions
63 lines (53 loc) · 2.52 KB
/
GPUWebScraper.py
File metadata and controls
63 lines (53 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from bs4 import BeautifulSoup
import requests
import re
import GetProductAvailability
#Given a search url, list the first 12 products that show up
#Only 12 becasue of lazy loading
url = "https://www.canadacomputers.com/en/powered-by-intel/266476/asrock-intel-arc-b580-steel-legend-12gb-gddr6-oc-battlemage-gpu-b580-sl-12go.html"
def displayStockOfSearchResult(URL) -> str:
'''
Given a URL of a search in Canada Computers
Return a string with the stock information of the first 12 items
'''
results = requests.get(URL)
doc = BeautifulSoup(results.text,"html.parser")
displayString = ""
#List of all the graphics card with the URL search above
products = doc.find_all(id=re.compile(r"product_card_\d+"))
if products:
for product in products:
print(product)
productTitle = product.find(class_=re.compile(r"product-title"))
productLinkTag = productTitle.find("a")
href = productLinkTag.get("href","")
if (productString := GetProductAvailability.getInStockON(href)):
productString = GetProductAvailability.getInStockON(href) #Prints Product info
displayString += productLinkTag.text #Prints Name of Product
displayString += "\n=====================================\n"
displayString += productString
displayString += "\n"
else:
displayString += "None in Stock\n\n"
return displayString
else:
return ("No Products Found with url: " + url)
def checkIfInStock() -> None|str:
'''
Function specifically made for bot to run to find intel b580 stock
Returns product info if a item appears in stock after a search result, else None
'''
url = "https://www.canadacomputers.com/en/powered-by-intel/266476/asrock-intel-arc-b580-steel-legend-12gb-gddr6-oc-battlemage-gpu-b580-sl-12go.html"
results = requests.get(url)
doc = BeautifulSoup(results.text,"html.parser")
#List of all the graphics card with the URL search above
products = doc.find_all(id=re.compile(r"product_card_\d+"))
productTitle = doc.find(class_=re.compile(r"product-title"))
if products:
for product in products:
productTitle = product.find(class_=re.compile(r"product-title"))
productLinkTag = productTitle.find("a")
href = productLinkTag.get("href","")
if (output:= GetProductAvailability.getInStockON(href)):
return output
return None