我一直在为我正在使用scrapy制作的一个网站苦恼。 这个网站用产品数据返回一系列的Javascript变量(数组)。
datos[0] = ["12345","3M YELLOW CAT5E CABLE","6.81","1","A","N","N","N","N","N",0,0,0,0,0,"0","0","0","0","0","P","001-0030","12","40K8957","28396","250","Due: 30-12-1899",0.0000,1,"",\'\'];
datos[1] = ["12346","3M GREEN CAT5E CABLE","7.81","1","A","N","N","N","N","N",0,0,0,0,0,"0","0","0","0","0","P","001-0030","12","40K8957","28396","250","Due: 30-12-1899",0.0000,1,"",\'\'];
So on...
用scrapy将数组取为字符串是很容易的,因为网站的响应会打印出这些变量。
问题是我想把它转化为Json,这样我就可以处理它并把它存储在数据库表中。
通常我会用Javascript的函数Json.stringify将其转换为Json并在PHP中发布。
然而,当使用Python的json.load,甚至StringIO时,我无法将数组加载到json。
可能是一个格式错误,但我无法识别它,因为我不是Json或Python专家。
EDIT:
我刚刚意识到,既然Scrapy不能执行Javascript,那么主要问题是数据只是一个字符串。我应该把它格式化为Json格式。
我们非常欢迎任何帮助。