2017-10-12 114 views
-1

我想解析来自网站的订单。订单通过ajax加载和请求看起来像:Scrapy多部分表单数据请求

-----------------------------1662842698634843362034232373 Content-Disposition: form-data; name="query" { orders(skip: 30, limit: 30, filter: {less3bids: false,withoutMyBids: false,title: "tests",contractual: true}) { total filtered orders { id type { id name } } } } -----------------------------1662842698634843362034232373--

我不明白如何需要发送请求。我想:

def after_login(self, content): 
    body = '''-----------------------------1662842698634843362034232373 
       Content-Disposition: form-data; name="query" 
       { 
       orders(skip: 30, limit: 30, filter: {less3bids: false,withoutMyBids: false,title: "tests",contractual: true}) { 
       total 
       filtered 
       orders { 
       id 
       type { id name } 
       } 
       } 
       } 
      -----------------------------1662842698634843362034232373-- 
      ''' 
      return scrapy.Request(
       url="https://somesite.com/graphqlapi?", 
       method='POST', 
       body=body, 
       headers={ 
        'Content-Type': 'multipart/form-data; boundary=---------------------------1662842698634843362034232373' 
       }, 
       callback=self.parse_orders) 

但现场返回错误:

Syntax Error GraphQL request (1:1) Unexpected <EOF>\n\n1: \n ^\n 

回答

0

看起来像火狐检查返回不正确的PARAMS。当我从chrome复制params时,请求正常工作。

相关问题