2capctha solver.NetworkException



我有以下问题。我写了一个解决验证码的程序。如果我在本地运行它,它可以正常工作,但是当我将它上传到vps服务器时,会弹出以下错误:

Traceback (most recent call last):
File "/home/heniu/stooq_captcha_solver/captcha_solver.py", line 61, in <module>
code = solver.get_result(id)
File "/home/heniu/.local/lib/python3.10/site-packages/twocaptcha/solver.py", line 469, in get_result
raise NetworkException
twocaptcha.solver.NetworkException

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
from twocaptcha import TwoCaptcha
chrome_options = Options()
chrome_options.add_argument("--headless=chrome")
driver = webdriver.Chrome(
executable_path='chromedriver',
options=chrome_options
)
url = "https://stooq.pl/db/h/"
print(f'Łączę ze stroną {url}')
driver.get(url)
driver.maximize_window()
time.sleep(3)
driver.implicitly_wait(5)
cookie_button = driver.find_element(
By.XPATH,
"/html/body/div/div[2]/div[1]/div[2]/div[2]/button[1]/p"
)
cookie_button.click()
time.sleep(3)
driver.implicitly_wait(15)
print('Pobieram obrazek')
download_link = driver.find_element(
By.XPATH,
"/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr/td/table[5]/tbody/tr/td/table/tbody/tr[2]/td[1]/table/tbody/tr[5]/td[3]/a"
)
download_link.click()
time.sleep(3)
driver.implicitly_wait(5)
captcha_img = driver.find_element(By.ID, "cpt_cd")
with open("captcha.png", "wb") as captcha:
captcha.write(captcha_img.screenshot_as_png)
print('Obrazek pobrany')
print('Rozwiązuję captchę')
solver = TwoCaptcha('api_key')
captcha_solve = solver.normal("captcha.png")
id = solver.send(file="captcha.png")
time.sleep(30)
code = solver.get_result(id)
print("Captcha rozwiązana")
captcha_text = driver.find_element(
By.XPATH,
"/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr/td/table[5]/tbody/tr/td/div[1]/div[1]/table/tbody/tr/td/table/tbody/tr[5]/td/input"
)
captcha_text.send_keys(code)
captcha_button = driver.find_element(
By.XPATH,
"/html/body/table/tbody/tr[2]/td[2]/table/tbody/tr/td/table/tbody/tr/td/table[5]/tbody/tr/td/div[1]/div[1]/table/tbody/tr/td/table/tbody/tr[6]/td/input"
)
captcha_button.click()
time.sleep(3)
driver.implicitly_wait(5)
print('Pobieram plik')
download_button = driver.find_element(By.ID, "cpt_gt")
download_button.click()
time.sleep(90)
driver.close()

行:

solver = TwoCaptcha('api_key')

我有正确的api_key

我试过改变等待时间,但是行不通。

在VPS上我安装了google_chrome_stable.

验证码图像下载是正确的,每当我运行程序,新的图像下载

不好意思。我解出来了。这足以大大延长解决方案的等待时间。之前我增加了10-15秒的等待时间。60秒工作

相关内容

  • 没有找到相关文章

最新更新