【问题标题】:Scrapy and Selenium submit form that renders dynamicallyScrapy 和 Selenium 提交动态呈现的表单
【发布时间】:2014-07-21 12:13:18
【问题描述】:

我使用 selenium 首先加载通过 ajax 生成的表单。

现在我无法将 selenium 响应传递给 scrapy FormReuqest 方法

发送表单数据值。

表单在用户提交之前进行了 jquery 验证,使用 scrapy 提交是否更难?

感谢任何帮助。

谢谢

【问题讨论】:

标签: python selenium web-scraping scrapy


【解决方案1】:

这里既不需要Scrapy,也不需要selenium。只需发出底层POST 请求并解析json 响应。使用requests 的示例:

import json
import requests


URL = 'http://calculator.shipito.com/en/rates'
data = {"location": "10", "country": "GB", "city": "London",
        "postalcode": "123456", 
        "packages": [{"dimensions_units": "in", "weight_units": "lbs", "dimension": {"width": "9", "height": "20.4", "length": "17"},
        "weight": "9", "value": "170"}]}

response = requests.post(URL, data=json.dumps(data))
print response.json()

打印:

[
    {u'infoUrl': u'http://www.shipito.com/postage#tnt', u'isPromoted': False, u'popularity': 1, u'name': u'TNT Economy', u'deliveryTime': 6, u'insurable': True, u'usesDimWeight': True, u'shippingRate': 68.38, u'separateShippingRate': None, u'bonusShippingRate': 68.38, u'deliveryTimeInfo': u'4-6 business days', u'mps': False, u'insuranceRate': 0, u'logoImg': u'tnt.png'}, 
    ...
]

【讨论】:

  • 是否可以使用纯scrapy.http.FormRequest.from_response() 方法?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-10-13
  • 2018-02-09
  • 2014-02-10
  • 2016-02-28
  • 1970-01-01
  • 1970-01-01
  • 2013-01-27
相关资源
最近更新 更多