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):
|
def get_register_link(self):
|
||||||
response = self.session.get(f"{self.base_url}/cm/showQrCode")
|
response = self.session.get(f"{self.base_url}/cm/showQrCode")
|
||||||
soup = BeautifulSoup(response.content, 'html.parser')
|
soup = BeautifulSoup(response.content, 'html.parser')
|
||||||
soup = soup.find('form', {'id': 'qrCodeForm'})
|
form = soup.find('form', {'id': 'qrCodeForm'})
|
||||||
return soup.find('a')['href']
|
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):
|
def get_generate_username(self, max_username_index: int):
|
||||||
max_username_index += 1
|
max_username_index += 1
|
||||||
@ -515,12 +528,10 @@ class CM_BOT:
|
|||||||
soup = BeautifulSoup(response.content, 'html.parser')
|
soup = BeautifulSoup(response.content, 'html.parser')
|
||||||
try:
|
try:
|
||||||
return round(float(soup.find('table', {'class': 'generalContent'}).find(text=re.compile('Credit Available')).parent.parent.find_all('td')[2].text.replace(",","")), 2)
|
return round(float(soup.find('table', {'class': 'generalContent'}).find(text=re.compile('Credit Available')).parent.parent.find_all('td')[2].text.replace(",","")), 2)
|
||||||
except:
|
except Exception as exc:
|
||||||
print(f"Error getting credit.")
|
self._dump_html("get_user_credit", response.content)
|
||||||
now = datetime.datetime.now().strftime('%Y%m%d_%H%M')
|
print(f"Error getting credit: {exc}")
|
||||||
# with open(f'credit-{now}.html', 'wb') as f:
|
return 0
|
||||||
# f.write(response.content)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def get_transfer_token(self):
|
def get_transfer_token(self):
|
||||||
response = self.session.get(f'{self.base_url}/cm/transfer')
|
response = self.session.get(f'{self.base_url}/cm/transfer')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user