【发布时间】:2015-01-14 16:54:59
【问题描述】:
我在站点https://www.barefootstudent.com/jobs 中使用scrapy 提交表单(任何指向页面的链接等http://www.barefootstudent.com/los_angeles/jobs/full_time/full_time_nanny_needed_in_venice_217021)
我的 scapy 机器人成功登录,但我无法避免验证码。 对于表单提交,我使用 scrapy.FormRequest.from_reponse
frq = scrapy.FormRequest.from_response(response, formdata={'message': 'itttttttt',
'security': captcha, 'name': 'fx',
'category_id': '2', 'email': 'ololo%40gmail.com', 'item_id': '216640_2', 'location': '18', 'send_message': 'Send%20Message'
}, callback=self.afterForm)
yield frq
我想从此页面加载验证码图像,并手动输入脚本运行时。 等等
captcha = raw_input("put captcha in manually>")
我试试
urllib.urlretrieve(captcha, "./captcha.jpg")
但是这个方法加载了不正确的验证码(网站拒绝了我的输入)。我尝试在一个运行脚本中反复调用 urllib.urlretieve 并且每次他返回不同的验证码:(
之后我尝试使用 ImagePipeline。 但我的问题是 return item(下载图像)仅在函数执行完成后才会发生,即使我使用 yeild。
item = BfsItem()
item['image_urls'] = [captcha]
yield item
captcha = raw_input("put captcha in manually>")
frq = scrapy.FormRequest.from_response(response, formdata={'message': 'itttttttt',
'security': captcha, 'name': 'fx',
'category_id': '2', 'email': 'ololo%40gmail.com', 'item_id': '216640_2', 'location': '18', 'send_message': 'Send%20Message'
}, callback=self.afterForm)
yield frq
那一刻,当我的脚本请求输入时,图片没有下载!
我如何修改我的脚本并在手动输入验证码后调用 FormRequest?
非常感谢!
【问题讨论】: