python 2capcta求解器,网络异常

disho6za  于 2023-01-12  发布在  Python
关注(0)|答案(1)|浏览(124)

我有以下问题,我写了一个解决验证码的程序,如果我在本地运行它,它工作起来没有问题,但当我上传到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。
验证码图像下载是正确的,每当我运行程序,新的图像下载

db2dz4w8

db2dz4w81#

抱歉,麻烦了。我解决了这个问题。这足以大大延长等待解决方案的时间。之前我增加了10-15秒的等待时间。60秒工作

相关问题