Skip to content

Commit 2b0c1f3

Browse files
committed
fix: prevent method calls on None
1 parent 4d9ab96 commit 2b0c1f3

6 files changed

Lines changed: 22 additions & 11 deletions

File tree

graphicnovelpricescraper/retailers/amazon.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ async def scrape(self, isbn: str, title: str) -> GraphicNovel:
3535
price_fraction = await page.locator(
3636
"span.a-price-fraction"
3737
).first.text_content()
38-
price = float(f"{price_whole}{price_fraction}")
38+
if price_whole and price_fraction:
39+
price_whole = price_whole.strip()
40+
price_fraction = price_fraction.strip()
41+
price = float(f"{price_whole}{price_fraction}")
3942

4043
href = await page.locator(
4144
"div[data-cy='title-recipe'] a"
4245
).first.get_attribute("href")
4346
if href:
4447
href = href.strip().split("?", 1)[0]
45-
url = f"https://www.amazon.com{href}"
48+
url = f"https://www.amazon.com{href}"
4649
except Exception as e:
4750
print(f"Unable to scrape {isbn} from Amazon: {e}")
4851
finally:

graphicnovelpricescraper/retailers/barnesandnoble.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ async def scrape(self, isbn: str, title: str) -> GraphicNovel:
3232
price_text = await page.locator(
3333
".product-item-card__current-price"
3434
).first.text_content()
35-
price = float(price_text.replace("$", "").strip())
35+
if price_text:
36+
price_text = price_text.strip()
37+
price = float(price_text.replace("$", ""))
3638

3739
href = (
3840
await page.locator(".product-item-card__title")
@@ -41,7 +43,7 @@ async def scrape(self, isbn: str, title: str) -> GraphicNovel:
4143
)
4244
if href:
4345
href = href.strip().split("?", 1)[0]
44-
url = f"https://www.barnesandnoble.com{href}"
46+
url = f"https://www.barnesandnoble.com{href}"
4547
except Exception as e:
4648
print(f"Unable to scrape {isbn} from Barnes & Noble: {e}")
4749
finally:

graphicnovelpricescraper/retailers/cheapgraphicnovels.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,14 @@ async def scrape(self, isbn: str, title: str) -> GraphicNovel:
3535
title = title.strip()
3636

3737
price_text = await page.locator(".price.product-price").first.text_content()
38-
price = float(price_text.replace("$", "").strip())
38+
if price_text:
39+
price_text = price_text.strip()
40+
price = float(price_text.replace("$", ""))
3941

4042
href = await page.locator(".fn.url").first.get_attribute("href")
4143
if href:
4244
href = href.strip().split("?", 1)[0]
43-
url = f"https://cheapgraphicnovels.com/{href}"
45+
url = f"https://cheapgraphicnovels.com/{href}"
4446
except Exception as e:
4547
print(f"Unable to scrape {isbn} from Cheap Graphic Novels: {e}")
4648
finally:

graphicnovelpricescraper/retailers/instocktrades.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ async def scrape(self, isbn: str, title: str) -> GraphicNovel:
4444
title = await page.locator(".title").first.inner_text()
4545

4646
price_text = await page.locator(".price").first.inner_text()
47-
price = float(price_text.replace("$", "").strip())
47+
if price_text:
48+
price_text = price_text.strip()
49+
price = float(price_text.replace("$", ""))
4850

4951
href = await page.locator(".title a").first.get_attribute("href")
5052
if href:
5153
href = href.strip().split("?", 1)[0]
52-
url = f"https://www.instocktrades.com{href}"
54+
url = f"https://www.instocktrades.com{href}"
5355
else:
5456
title = ""
5557
except Exception as e:

graphicnovelpricescraper/retailers/organicpricedbooks.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,16 @@ async def scrape(self, isbn: str, title: str) -> GraphicNovel:
3434
price_text = await page.locator(
3535
"span.price-item.price-item--sale.price-item--last"
3636
).first.inner_text()
37-
price = float(price_text.replace("$", "").replace("USD", "").strip())
37+
if price_text:
38+
price_text = price_text.strip()
39+
price = float(price_text.replace("$", "").replace("USD", ""))
3840

3941
href = await page.locator("a.full-unstyled-link").first.get_attribute(
4042
"href"
4143
)
4244
if href:
4345
href = href.strip().split("?", 1)[0]
44-
url = f"https://www.panelboundcomics.com{href}"
46+
url = f"https://www.panelboundcomics.com{href}"
4547
else:
4648
title = ""
4749
except Exception as e:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "graphicnovelpricescraper"
7-
version = "0.1.1"
7+
version = "0.1.2"
88
dependencies = [
99
"playwright>=1.60.0"
1010
]

0 commit comments

Comments
 (0)