提取验证码图像

2024-09-29 23:17:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在为神经元网络建立训练集,从CAPTCHA图像中提取不同的数字。 我使用的是python2.7.3、lxml库和XPath选择器。在

为了从captcha获得正确的图像,我需要提取img src,它是动态加载到www中的,每次都是不同的,所以我的Python代码是:

import urllib
from lxml import etree, html

adres_prefix = "https://prod.ceidg.gov.pl/CEIDG/CEIDG.Public.UI/"
adres_sufix = etree.XPath('string(//img[@class="captcha"]/@src)')
sock = urllib.urlopen("https://prod.ceidg.gov.pl/CEIDG/CEIDG.Public.UI/Search.aspx")
htmlSource = sock.read()                             
sock.close()
root = etree.HTML(htmlSource)
result = etree.tostring(root, pretty_print=True, method="html")
result2 = adres_sufix(root)
www = adres_prefix + result2
print www

所以每次我得到www:

^{pr2}$

有什么不对,因为当我把这个链接复制到我的浏览器里时,我什么也得不到。在

带有CAPTCHA的源页

我不知道怎么了。为什么XPath选择器获取'&empty=1'? 有什么想法吗?在


Tags: 图像importsrcimgwww选择器rootlxml

热门问题