здесь полные журналы ошибок
line 514, in wrap_api_call
raise rewrite_error(error, f"{parsed_st['apiName']}: {error}") from None
ValueError: Page.evaluate: The future belongs to a different loop than the one specified as the loop argument
Я пытаюсь нажать кнопку «Отправить» после получения ответа от API. мой полный код
import scrapy
from anticaptchaofficial.recaptchav2proxyless import recaptchaV2Proxyless
from scrapy_playwright.page import PageMethod
class RecaptchaSpider(scrapy.Spider):
name = "recaptcha_spider"
start_urls = ["https://www.google.com/recaptcha/api2/demo"]
delay_after_submit = 5 # Time in seconds to wait after submit
def start_requests(self):
for url in self.start_urls:
yield scrapy.Request(
url,
dont_filter=True,
meta={
"playwright": True,
"playwright_include_page": True,
},
callback=self.solve_captcha,
)
async def solve_captcha(self, response):
# Step 1: Solve the CAPTCHA using AntiCaptcha API
api_key = "my api key" # Replace with your actual API key
solver = recaptchaV2Proxyless()
solver.set_key(api_key)
solver.set_website_url(response.url)
solver.set_website_key("6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-") # Replace with Google reCAPTCHA site key
captcha_solution = solver.solve_and_return_solution()
if captcha_solution:
self.logger.info(f"Solved CAPTCHA: {captcha_solution}")
# Step 2: Execute JavaScript to fill the CAPTCHA solution and click the submit button
page = response.meta["playwright_page"]
await page.evaluate(f'document.getElementById("g-recaptcha-response").innerHTML = "{captcha_solution}";') # Replace with the correct ID if different
await page.click("button[type='submit']") # Replace with the correct selector for the submit button
# Wait for the next page or any other action you want to perform
await page.wait_for_timeout(self.delay_after_submit)
# Step 3: Handle the next step after clicking submit (if necessary)
# You might want to retrieve the new page content here
new_content = await page.content()
self.logger.info("New page content after submit:")
self.logger.info(new_content)
else:
self.logger.error("Failed to solve CAPTCHA.")
Подробнее здесь: https://stackoverflow.com/questions/790 ... future-bel