将string解析成xml报错
def parse(self, response):
# 解析json,获取某个变量var的值
# /html/body/script[1]/text()
print(1)
json_str = response.xpath('//html/body/script[1]/text()').extract_first()
demo = response.text
soup = BeautifulSoup(demo, 'lxml')
script = soup.select('body script')[0].string
print(script)
script_text = js2xml.parse(script, "text/xml")
script_tree = js2xml.pretty_print(script_text)
selector = etree.HTML(script_tree)
calmjs.parse.exceptions.ECMASyntaxError: Unexpected 'const' at 9:3 after ';' at 6:48
正确解析
发现可能是版本问题,js2xml解析不了const关键字,然后我就直接粗暴的替换const为var ,然后正常解析。