import scrapy
from scrapy.http import Request,FormRequest
class TySpider(scrapy.Spider):
name = 'ty'
allowed_domains = ['iqianyue.com']
#start_urls = ['http://iqianyue.com/']
header={ 'User-Agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)'}
def start_requests(self):
return [Request('http://edu.iqianyue.com/index_user_login.html',meta={'cookiejar':1},callback=self.parse)]
def parse(self, response):
data = {
'number':'xiesongyou',
'passwd':'xsy667437',
}
print("登录中.....")
return [FormRequest.from_response(response,
meta={'cookiejar':response.meta['cookiejar']},
headers=self.header,
formdata=data,
callback=self.next,)]
def next(self,response):
# rst=response.body
# print(rst.decode())
print(response.xpath("/html/head/title/text()").extract())
yield Request('http://edu.iqianyue.com/index_user_index.html',
callback=self.next2,
meta={"cookiejar":True})
def next2(self,response):
print(response.xpath("/html/head/title/text()").extract())
# rst = response.body
# print('- ' * 60)
# print(rst.decode())