飞客茶馆【flyertea】代码登录过程

登录网址:https://u.flyertea.com/login

飞客茶馆【flyertea】代码登录过程_第1张图片
image.png

这个登录页面还是比较简单的, 里面有个token hidden字段,获取一下,直接post过去即刻。
附上Scrapy登录代码:

# -*- coding: utf-8 -*-
import scrapy
from scrapy import Request, FormRequest

class LoginSpider(scrapy.Spider):
  name = 'login'
#    start_urls = ['http://flytea.com/']

  def start_requests(self):
      yield Request('https://u.flyertea.com/login', callback=self.parse_welcome)

  def parse_welcome(self, response):
      token = response.xpath('//input[@name="_token"]/@value').extract()[0]
  yield FormRequest.from_response(response, formdata={
          "_token": token,
          "username": "xxxxxxxxxx", "password":"xxxxxx",
          "s_countrycode":"CN", "s_mobile":"", "captcha":"","v_code":"","login_type":"0",
      "btnLogin":"登录"
  }, callback=self.parse_login)

  def parse_login(self, response):
      yield Request('https://www.flyertea.com/thread-2498141-2-1.html')

  def parse(self, response):
      print response.text

接下来可以走自己的业务流程~

你可能感兴趣的:(飞客茶馆【flyertea】代码登录过程)