1. 程式人生 > >scrapy之POST請求

scrapy之POST請求

from scrapy.spider import CrawlSpider
from scrapy.selector import Selector
import scrapy
import json
class LaGou(CrawlSpider):
    name = 'myspider'
    def start_requests(self):
        yield scrapy.FormRequest(
            url='https://www.******.com/jobs/positionAjax.json?city=%E5%B9%BF%E5%B7%9E&needAddtionalResult=false',
            formdata={
                'first': 'true',#這裡不能給bool型別的True,requests模組中可以
                'pn': '1',#這裡不能給int型別的1,requests模組中可以
                'kd': 'python'
            },
            callback=self.parse
        )
    def parse(self, response):
        datas=json.loads(response.body.decode())['content']['positionResult']['result']
        for data in datas:
            print(data['companyFullName'] + str(data['positionId']))