一旦您通过脚本获得了文本
js_text = soup.find('script', type="text/javascript").text例如。然后,您可以使用正则表达式来查找数据,我敢肯定有一种更简单的方法可以做到这一点,但是正则表达式也不应该很困难。
import reregex = re.compile('n^(.*?):(.*?)$|,', re.MULTILINE) #compile regexjs_text = re.findall(regex, js_text) # find first item @ new line to : and 2nd item @ from : to the end of the line or , js_text = [jt.strip() for jt in js_text] # to strip away all of the extra white space.这将以name | value | name2 | value2 …的顺序返回名称和值的列表,您以后可以将其弄乱或转换为字典。



