使用scrapy时出现错误
ValueError:json.dumps(form_data)时没有足够的值可解压缩(预期2,得到1)
我的代码如下:
form_data = {"directory_search_id":"12093",
"elements":{ "0" : {"id":"38",
"label":"Name First",
"attribute_id":"0",
"attribute_type_label_id":"0",
"attribute_part_id": "31",
"value":""},
"1" : {"id": "39",
"label":"Name Last",
"attribute_id":"0",
"attribute_type_label_id":"0",
"attribute_part_id":"34",
"value":""},
"2" : {"id":"37",
"label":"PFB License Number",
"attribute_id":"10028676",
"attribute_type_label_id":"0",
"attribute_part_id":"0",
"value":""},
"3" : {"id":"35",
"label":"Counties of Practice",
"attribute_id":"10028670",
"attribute_type_label_id":"0",
"attribute_part_id":"0",
"value_ids":{"0" : "235934"}},
"4" : {"id":"33",
"label":"Fiduciary Specialties",
"attribute_id":"10028672",
"attribute_type_label_id":"0",
"attribute_part_id":"0",
"value_ids":{"" : ""}},
"5" : {"id":"34",
"label":"Languages",
"attribute_id":"10028671",
"attribute_type_label_id":"0",
"attribute_part_id":"0",
"value_ids":{"" : ""}}}
}
print(self.start_urls)
response = FormRequest(url=self.start_urls[0],
formdata=json.dumps(form_data),
callback=self.parse_contents)
def parse_contents(self, response):
open_in_browser(response)
我遇到了这些错误:
2019-09-17 21:04:19 ERROR scraper 158: Spider error processing <GET
https://pfac.memberclicks.net/fiduciary-search#//> (referer: None)
Traceback (most recent call last):
File "/home/fairoos/projects/venvs/truelink/lib/python3.6/site-
packages/twisted/internet/defer.py", line 654, in _runCallbacks
current.result = callback(current.result, *args, **kw)
File "/home/fairoos/projects/truelinkscraping/TrueLinkScraping/spiders/pfac.py", line 73, in parse
callback=self.parse_contents)
File "/home/fairoos/projects/venvs/truelink/lib/python3.6/site-packages/scrapy/http/request/form.py", line 31, in __init__
querystr = _urlencode(items, self.encoding)
File "/home/fairoos/projects/venvs/truelink/lib/python3.6/site-packages/scrapy/http/request/form.py", line 66, in _urlencode
for k, vs in seq
File "/home/fairoos/projects/venvs/truelink/lib/python3.6/site-packages/scrapy/http/request/form.py", line 66, in <listcomp>
for k, vs in seq
ValueError: not enough values to unpack (expected 2, got 1)
我将字典中的所有int
都转换为str
,但仍然出现这些错误。