【问题标题】:Scrapy - Passing Parameters In URLsScrapy - 在 URL 中传递参数
【发布时间】:2019-08-27 09:17:15
【问题描述】:

如果我们使用requests并且我们需要在URL中传递参数,我们可以使用params

import requests


params = (
    ('q', 'scrapy'),
)

response = requests.get('https://github.com/search', params=params)

response.url 将是

In [4]: response.url                                                                                                                                            
Out[4]: 'https://github.com/search?q=scrapy'

https://2.python-requests.org//en/latest/user/quickstart/#passing-parameters-in-urls
但是如果我们使用 Scrapy,如何在 URL 中传递参数呢?

【问题讨论】:

    标签: python python-3.x request scrapy python-requests


    【解决方案1】:

    需要将FormRequest与GET方法一起使用并在formdata中传递params

            return FormRequest(url='https://github.com/search',
                               method='GET',
                               headers=headers,
                               formdata=params,
                               callback=self.parse_data)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-19
      • 2016-03-26
      • 1970-01-01
      • 2018-07-05
      • 1970-01-01
      • 2013-08-17
      • 2021-04-17
      • 1970-01-01
      相关资源
      最近更新 更多