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