Scrapy和Selenium提交动态呈现的表单

时间:2014-07-21 12:13:19

标签: python selenium web-scraping scrapy

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

现在我有麻烦将硒响应传递给scrapy FormReuqest方法

发送表单数据值。

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

感谢任何帮助。

感谢

1 个答案:

答案 0 :(得分:0)

您不需要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'}, 
    ...
]