Skip to content

Commit

Permalink
fix soup parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bbilly1 committed Feb 20, 2024
1 parent 046603b commit d8f54da
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions tilefy/src/plugins/chrome_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,30 @@ def __init__(self, extension_id):
def get(self):
"""get parsed users"""
soup = self.get_soup()
if not soup:
return 0

users = self.parse_field(soup)

return users

def get_soup(self):
"""get the soup"""
url = f"https://chromewebstore.google.com/detail/tubearchivist-companion/{self.extension_id}?hl=en&authuser=0" # noqa: E501
response = requests.get(url, headers=self.HEADERS)
response = requests.get(url, headers=self.HEADERS, timeout=30)
if not response.ok:
print(
f"failed to get {url}, {response.status_code} {response.text}"
)
return None

soup = BeautifulSoup(response.text, "html.parser")

return soup

def parse_field(self, soup):
"""extract the number"""
char_field = soup.find("span", {"class": "e-f-ih"}).text
char_field = soup.find("div", {"class": "F9iKBc"}).text
users = int(re.sub(r"[^\d]+", "", char_field))

return users

0 comments on commit d8f54da

Please sign in to comment.