refactor(scraper): make get_register_link and get_user_credit dump on failure
This commit is contained in:
parent
698e5bf22a
commit
e68e64065a
@ -452,8 +452,21 @@ class CM_BOT:
|
||||
def get_register_link(self):
|
||||
response = self.session.get(f"{self.base_url}/cm/showQrCode")
|
||||
soup = BeautifulSoup(response.content, 'html.parser')
|
||||
soup = soup.find('form', {'id': 'qrCodeForm'})
|
||||
return soup.find('a')['href']
|
||||
form = soup.find('form', {'id': 'qrCodeForm'})
|
||||
if form is None:
|
||||
path = self._dump_html("register_link_form", response.content)
|
||||
raise ScraperError(
|
||||
f"register_link: form#qrCodeForm not found "
|
||||
f"(response saved to {path})"
|
||||
)
|
||||
anchor = form.find('a')
|
||||
if anchor is None or 'href' not in anchor.attrs:
|
||||
path = self._dump_html("register_link_anchor", response.content)
|
||||
raise ScraperError(
|
||||
f"register_link: <a href> inside form#qrCodeForm not found "
|
||||
f"(response saved to {path})"
|
||||
)
|
||||
return anchor['href']
|
||||
|
||||
def get_generate_username(self, max_username_index: int):
|
||||
max_username_index += 1
|
||||
@ -515,11 +528,9 @@ class CM_BOT:
|
||||
soup = BeautifulSoup(response.content, 'html.parser')
|
||||
try:
|
||||
return round(float(soup.find('table', {'class': 'generalContent'}).find(text=re.compile('Credit Available')).parent.parent.find_all('td')[2].text.replace(",","")), 2)
|
||||
except:
|
||||
print(f"Error getting credit.")
|
||||
now = datetime.datetime.now().strftime('%Y%m%d_%H%M')
|
||||
# with open(f'credit-{now}.html', 'wb') as f:
|
||||
# f.write(response.content)
|
||||
except Exception as exc:
|
||||
self._dump_html("get_user_credit", response.content)
|
||||
print(f"Error getting credit: {exc}")
|
||||
return 0
|
||||
|
||||
def get_transfer_token(self):
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user