我正在为神经元网络建立训练集,从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'? 有什么想法吗?在
原始的HTML源代码确实有“empty=1”,因此您的代码是正确的。要获得图像,只需修剪掉“&;empty=1”部分。在
{a1}
相关问题 更多 >
编程相关推荐