Parse response and delegate the work to the client

pull/915/head
Moist-Cat 1 year ago
parent c5ec5ca2ee
commit 5acac97ae8

@ -1,5 +1,6 @@
from app.models.config import Config
from app.utils.misc import read_config_bool
from app.utils import captcha
from datetime import datetime
from defusedxml import ElementTree as ET
import random
@ -330,6 +331,11 @@ class Request:
proxies=self.proxies,
headers=headers,
cookies=cookies)
if response.status_code == "429":
# google's CAPTCHA
# we have to handle it here because we filter out scripts from the page source
# later
captcha.solve(response.text)
# Retry query with new identity if using Tor (max 10 attempts)
if 'form id="captcha-form"' in response.text and self.tor:

@ -318,17 +318,6 @@ def search():
translation = app.config['TRANSLATIONS'][localization_lang]
translate_to = localization_lang.replace('lang_', '')
# Return 503 if temporarily blocked by captcha
if has_captcha(str(response)):
return render_template(
'error.html',
blocked=True,
error_message=translation['ratelimit'],
translation=translation,
farside='https://farside.link',
config=g.user_config,
query=urlparse.unquote(query),
params=g.user_config.to_params(keys=['preferences'])), 503
response = bold_search_terms(response, query)
# Feature to display IP address

@ -0,0 +1,24 @@
import os
from bs4 import BeautifulSoup as bs
try:
import deathbycaptcha
except ImportError:
deathbycaptcha = None
def parse_params(response):
params = {
"googlekey":"",
"data-s": "",
"pageurl": ""
}
soup = bs(response)
def solve(response):
if deathbycaptcha is None:
raise ImportError("The deathbycaptcha client is not installed")
client = deathbycaptcha.HttpClient(
os.env.get("DBC_USER", "username"),
os.env.get("DBC_PASS")
)
Loading…
Cancel
Save