问题遇到的现象和发生背景
将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
我想要达到的结果
正确解析