1.如果你的爬虫使用webdriver来作为访问页面,用什么scrapy自带的post form表单来登陆是不行的。因为你的session不是同一个会话,所以你必须在webdriver来进行添加cookie的方法
方法1:
# 设置无头模式 浏览器就不会弹出来
opts = FirefoxOptions()
opts.add_argument("--headless")
firefox_options = opts
driver = wb.Firefox(firefox_options = opts)
driver.implicitly_wait(3)
# print "11111111111111111111111"
click_url = "xxx.com/click"
driver.get(request.url)
if request.url != click_url and request.url != "xxx.com/login":
# print 22222222222222
page = driver.page_source
driver.close()
return HtmlResponse(request.url, body=page, encoding='utf-8', request=request, )
used_selenium = request.meta.get('usedSelenium', False)
if used_selenium:
click_a = '//a[@class=