我在做一个招标网的爬虫
http://bs.gdggzy.org.cn/osh-web/project/projectbulletin/bulletinList?queryType=1&orgCode=gd&tradeTypeId=GovernmentProcurement&tradeItemId=zf_res_bulletin
每隔一段时间进入网站就需要填写验证码,所以我想每一次运行scrapy时先判断网站需不需要填验证码,如果需要,就用selenium截图上传验证码识别平台来通过验证,并获得当前网页cookie来向下一个parse传递
我的selenium代码是写在start_request中的
def start_requests(self):
for url in self.start_urls:
driver_path = 'C:/Users/AppData/Local/Google/Chrome/Application/chromedriver.exe'
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-automation'])
browser = webdriver.Chrome(executable_path=driver_path, options=options)
browser.get(url=url)
WebDriverWait(browser, 10, 0.2).until(lambda x: x.find_element_by_xpath("//head//title"))
往下就是获取验证码截图、上传图片、输入验证码的操作
我看日志的话就是执行完上面那段打开了浏览器,浏览器显示页面后秒关,下面的代码没有执行,这是为什么呢?