将非str formdata传递给FormRequest

时间:2017-08-08 14:19:04

标签: python scrapy

我有一个POST请求,我需要制作我想要抓取的产品,请求formdata有点复杂,Scrapy不能接受它的方式,我该如何解决这个问题?< / p>

Formdata

{
  "requests": [
    {
      "indexName": "egypt_products",
      "params": "query=&hitsPerPage=24&maxValuesPerFacet=20&page=1&attributesToRetrieve=permalink%2Cpermalink_ar%2Cpost_title%2Cpost_title_ar%2Cdiscount%2Cdiscount_val%2Cimages%2Cprice%2Cpromotion_offer_json%2Cregular_price%2Csale_price%2Cin_stock&attributesToHighlight=post_title%2Cpost_title_ar&getRankingInfo=1&facetFilters=%5B%5B%22taxonomies.taxonomies_hierarchical.product_cat.lvl0%3AMobiles%20%26%20Tablets%22%5D%5D&facets=%5B%22taxonomies_ar.attr.Brand%22%2C%22taxonomies_ar.attr.Processor%22%2C%22taxonomies_ar.attr.Screen%20Size%22%2C%22taxonomies_ar.attr.Internal%20Memory%22%2C%22taxonomies_ar.attr.Storage%20Size%22%2C%22taxonomies_ar.attr.RAM%22%2C%22taxonomies_ar.attr.Graphics%20Card%22%2C%22taxonomies_ar.attr.Color%22%2C%22taxonomies_ar.attr.OS%22%2C%22taxonomies_ar.attr.Megapixel%22%2C%22price%22%2C%22taxonomies_ar.product_cat%22%2C%22taxonomies.taxonomies_hierarchical.product_cat.lvl0%22%2C%22taxonomies.taxonomies_hierarchical.product_cat.lvl1%22%5D&tagFilters="
    },
    {
      "indexName": "egypt_products",
      "params": "query=&hitsPerPage=1&maxValuesPerFacet=20&page=0&attributesToRetrieve=%5B%5D&attributesToHighlight=%5B%5D&getRankingInfo=1&facetFilters=%5B%5B%22taxonomies.taxonomies_hierarchical.product_cat.lvl0%3AMobiles%20%26%20Tablets%22%5D%5D&attributesToSnippet=%5B%5D&tagFilters=&facets=%5B%22taxonomies.taxonomies_hierarchical.product_cat.lvl0%22%5D"
    }
  ]
}

代码:

ajax_request = FormRequest(url=self.products_ajax_api,
                           formdata=request_payload,
                           meta={'category_name': category},
                           dont_filter=True,
                           callback=self.post_ajax_request_category)

其中request_payload是JSON数据。 问题是formdata接受以下格式{'str': 'str'}的字典,但不接受我的情况下的嵌套字典。

0 个答案:

没有答案