Git Product home page Git Product logo

Comments (3)

Germey avatar Germey commented on September 2, 2024

比如你在页面中看到的显示的验证码为1234,然后附带Cookies请求了一下验证码的图片,由于验证码的图片是请求一次变一次,所以当前你识别出来的验证码可能是改变的5678,和原先就是不一样了,只是识别的结果和当前你看到的结果不同。但是不影响识别,都加上Cookies直接提交就好了。

from cookiespool.

hanfuyin avatar hanfuyin commented on September 2, 2024

我就是这样提交的,但是不知道为什么和当前用户就是关联不上。后来我用截屏的方式,可以了。
谢谢大哥的回复

from cookiespool.

hanfuyin avatar hanfuyin commented on September 2, 2024

再请教一个问题
linux : centos7 server
Chrome : 59.0.3071.109
做的是微博爬虫程序,因为频率限制会弹出验证码。经过多次试验以下代码在windows下没有问题。在linux下确不奏效,也没有返回任何报错信息。请问我这问题在哪里?
以下代码是在linux下执行的代码,windows下去掉Xvfb

vdisplay = Xvfb()
vdisplay.start()

chrome_options = Options()
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-setuid-sandbox")

self.browser = webdriver.Chrome(chrome_options=chrome_options)
self.browser.set_window_size(1200, 900)
url = url
self.browser.get(url)

self.browser.delete_all_cookies()

cookieStr = eval(cookieStr)

for cookies in cookieStr:
    self.browser.add_cookie(eval('{"name":"'+cookies+'","value":"'+cookieStr[cookies]+'"}'))

self.browser.get(url)

wait = WebDriverWait(self.browser, 20)

try:
    backImg = str(uuid.uuid1()) + '.png'
    self.browser.save_screenshot(backImg)
    self.browser.get_screenshot_as_png()

    screenshot = Image.open(backImg)
    yzm = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.code_img img')))

    location  = yzm.location                     # 获取验证码x,y轴坐标
    size      = yzm.size                         # 获取验证码的长宽
    rangle    = (int(location['x']), int(location['y']), int(location['x'] + size['width']), int(location['y'] + size['height']))
    caotcha   = screenshot.crop(rangle)
    verifyImg = str(uuid.uuid1()) + '2.png'
    caotcha.save(verifyImg)

   result = self.ydm.identify(file=verifyImg)
    if not result:
        print('验证码识别失败, 跳过识别')
        return

    door = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.code_input .W_inputStp')))

    door.send_keys(result)

    submit = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, '.S_btn_b')))
    typeS = submit.click()

    os.remove(verifyImg)
    os.remove(backImg)

    self.browser.quit()
    vdisplay.stop()
except WebDriverException as e:
    print(e.args)

from cookiespool.

Related Issues (7)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.