Skip to content

Commit

Permalink
Merge pull request #208 from Crinibus/fix-amazon-get-currency
Browse files Browse the repository at this point in the history
Fix getting currency in Amazon handler
  • Loading branch information
Crinibus authored Dec 14, 2022
2 parents d0310e9 + 5068a7a commit 08daed2
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions scraper/domains.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Dict
import requests
import urllib.parse
from bs4 import BeautifulSoup
import json
import logging
Expand Down Expand Up @@ -243,9 +244,30 @@ def _get_product_currency(self) -> str:
try:
return self.request_data.find("input", id="attach-currency-of-preference").get("value")
except (AttributeError, ValueError, TypeError):
return (
self.request_data.find("a", id="icp-touch-link-cop").find("span", class_="icp-color-base").text.split(" ")[0]
)
try:
return (
self.request_data.find("a", id="icp-touch-link-cop").find("span", class_="icp-color-base").text.split(" ")[0]
)
except (AttributeError, ValueError, TypeError):
raw_data = self.request_data.find_all(
"span",
class_="a-declarative",
attrs={
"data-action": "a-modal",
"data-csa-c-type": "widget",
"data-csa-c-func-deps": "aui-da-a-modal",
"data-a-modal": True,
},
)[1].get("data-a-modal")
json_data = json.loads(raw_data)
parsed_url = urllib.parse.unquote(json_data.get("url"))
currency = (
json.loads(parsed_url.replace("/af/sp-detail/feedback-form?pl=", ""))
.get("offerCollection")[0]
.get("priceInfo")
.get("currencyCode")
)
return currency

def _get_product_id(self) -> str:
try:
Expand Down

0 comments on commit 08daed2

Please sign in to comment.