代码拉取完成,页面将自动刷新
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
from chaojiying import Chaojiying
import logging
import time
logging.basicConfig(level=logging.INFO,
format='%(asctime)s - %(levelname)s: %(message)s')
username = 'Cthousand'
password = input('password:')
soft_id = '931779'
captcha_kind = '1006'
client = Chaojiying(username=username, password=password, soft_id=soft_id)
browser = webdriver.Chrome()
def login():
browser.get('https://captcha8.scrape.center/')
browser.find_element(
by=By.CSS_SELECTOR, value='.username input[type="text"]').send_keys('admin')
browser.find_element(
by=By.CSS_SELECTOR, value='.password input[type="password"]').send_keys('admin')
captcha = browser.find_element(
by=By.CSS_SELECTOR, value='#captcha').screenshot_as_png
with open('项目2/captcha/captcha.png', 'wb') as f:
f.write(captcha)
file_name = '项目2/captcha/captcha.png'
captcha_result = client.post_pic(
open(file_name, 'rb').read(), captcha_kind).get('pic_str')
time.sleep(1)
logging.info(f'captcha:{captcha_result}')
browser.find_element(
by=By.CSS_SELECTOR, value='.captcha input[type="text"]').send_keys(captcha_result)
browser.find_element(by=By.CSS_SELECTOR, value='.login').click()
try:
WebDriverWait(browser, 10).until(EC.presence_of_element_located(
(By.XPATH, '//h2[contains(., "登录成功")]')))
# browser.close()
logging.info('登录成功!')
except TimeoutException:
logging.error('超时!')
browser.close()
if __name__ == '__main__':
login()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。