Skip to content

Commit c37208f

Browse files
committed
add a webscraper that locates availability Model 4 Raspberry PIs
1 parent 11f98e6 commit c37208f

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

raspberry_pi_webscraper/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# raspberry-pi-webscraping
2+
3+
A simple Python script to check popular Raspberry PI-certified shops for availability of Model 4s.

raspberry_pi_webscraper/main.py

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import requests
2+
from bs4 import BeautifulSoup
3+
4+
def scrape_adafruit():
5+
url = "https://www.adafruit.com/product/4295"
6+
response = requests.get(url)
7+
8+
soup = BeautifulSoup(response.content, "html.parser")
9+
options = soup.find(class_="meta_pid_boxes").find_all("a")
10+
print("--- Adafruit ---")
11+
for option in options:
12+
status = option.find(class_="meta_pid_box_status").get_text().lower()
13+
ram_size = option.find(class_="stripes_oos_tag").get_text().strip()
14+
if "in" in status:
15+
print(ram_size, "is available -", url)
16+
print()
17+
18+
19+
def scrape_pishop_us():
20+
urls = {
21+
"1gb": "https://www.pishop.us/product/raspberry-pi-4-model-b-1gb/",
22+
"2gb": "https://www.pishop.us/product/raspberry-pi-4-model-b-2gb/",
23+
"4gb": "https://www.pishop.us/product/raspberry-pi-4-model-b-4gb/",
24+
"8gb": "https://www.pishop.us/product/raspberry-pi-4-model-b-8gb/",
25+
}
26+
print("--- PiShop US ---")
27+
for ram_size, url in urls.items():
28+
response = requests.get(url)
29+
soup = BeautifulSoup(response.content, "html.parser")
30+
status = soup.find(id="form-action-addToCart")["value"].lower()
31+
if "in" in status:
32+
print(ram_size, "is available -", url)
33+
print()
34+
35+
36+
def scrape_vilros():
37+
urls = {
38+
"1gb": "https://vilros.com/products/raspberry-pi-4-model-b",
39+
"2gb": "https://vilros.com/collections/raspberry-pi/products/raspberry-pi-4-2gb-ram",
40+
"4gb": "https://vilros.com/collections/raspberry-pi/products/raspberry-pi-4-4gb-ram",
41+
"8gb": "https://vilros.com/collections/raspberry-pi/products/raspberry-pi-4-model-b-8gb-ram",
42+
}
43+
print("--- Vilros ---")
44+
for ram_size, url in urls.items():
45+
response = requests.get(url)
46+
soup = BeautifulSoup(response.content, "html.parser")
47+
status = (
48+
soup.select("span[data-add-to-cart-text]")[0].get_text().strip().lower()
49+
)
50+
if "out" not in status:
51+
print(ram_size, "is available -", url)
52+
print()
53+
54+
55+
def scrape_chicago_electronics():
56+
urls = {
57+
"1gb": "https://chicagodist.com/products/raspberry-pi-4-model-b-1gb",
58+
"2gb": "https://chicagodist.com/products/raspberry-pi-4-model-b-2gb",
59+
"4gb": "https://chicagodist.com/products/raspberry-pi-4-model-b-4gb",
60+
"8gb": "https://chicagodist.com/products/raspberry-pi-4-model-b-8gb",
61+
}
62+
print("--- Chicago Electronic Distributors ---")
63+
for ram_size, url in urls.items():
64+
response = requests.get(url)
65+
soup = BeautifulSoup(response.content, "html.parser")
66+
status = soup.find(class_="modal_price").find("span").get_text().strip().lower()
67+
if "out" not in status:
68+
print(ram_size, "is available -", url)
69+
print()
70+
71+
72+
def scrape_okdo():
73+
urls = {
74+
"2gb": "https://www.okdo.com/us/p/raspberry-pi-4-model-b-2gb-2/"
75+
}
76+
print("--- OKdo ---")
77+
for ram_size, url in urls.items():
78+
response = requests.get(url)
79+
soup = BeautifulSoup(response.content, "html.parser")
80+
status = soup.find(class_="c-stock-level").get_text().strip().lower()
81+
if "out" not in status:
82+
print(ram_size, "is available -", url)
83+
print()
84+
85+
86+
def scrape_canakit():
87+
urls = {
88+
"1gb": "https://www.canakit.com/raspberry-pi-4.html",
89+
"2gb": "https://www.canakit.com/raspberry-pi-4-2gb.html",
90+
"4gb": "https://www.canakit.com/raspberry-pi-4-4gb.html",
91+
"8gb": "https://www.canakit.com/raspberry-pi-4-8gb.html",
92+
}
93+
print("--- Canakit ---")
94+
for ram_size, url in urls.items():
95+
response = requests.get(url)
96+
soup = BeautifulSoup(response.content, "html.parser")
97+
status = (
98+
soup.find(id="ProductAddToCartDiv").find("span").get_text().strip().lower()
99+
)
100+
if "out" not in status:
101+
print(ram_size, "is available -", url)
102+
print()
103+
104+
105+
def main():
106+
scrape_adafruit()
107+
scrape_pishop_us()
108+
scrape_vilros()
109+
scrape_chicago_electronics()
110+
scrape_okdo()
111+
scrape_canakit()
112+
113+
114+
if __name__ == "__main__":
115+
main()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
beautifulsoup4==4.11.1
2+
black==22.8.0
3+
bs4==0.0.1
4+
certifi==2022.9.24
5+
charset-normalizer==2.1.1
6+
click==8.1.3
7+
idna==3.4
8+
mypy-extensions==0.4.3
9+
pathspec==0.10.1
10+
platformdirs==2.5.2
11+
requests==2.28.1
12+
soupsieve==2.3.2.post1
13+
tomli==2.0.1
14+
urllib3==1.26.12

0 commit comments

Comments
 (0)