js变量的正则表达式以分号结尾
Regex for js variable end with semicolon
我正在尝试从 Javascript 代码中查找并提取 属性 对象的 属性 赋值,使用 BeautifulSoup 提取。我试过关注
re.findall(r"product_images\['top_lg'] = .*;", txt)
不幸的是,它没有从我下面的文本中提取任何内容。
product_images['top_lg'] = {
"tn": '//image.test.com/media/cache/04/0a/040a1e61f5edc387d8c8e40d3ea0e0ca.jpg',
"md": '//image.test.com/media/cache/b7/f3/b7f3cb1da267d7e8ac0412bdc522c862.jpg',
"lg": '//image.test.com/media/shape_images/011f7f24ae4cbbef191cff1a711df9e1_a3c9ca71b7d85d87085955f8d1c4bfc3_0_.jpg',
"alt": 'test ',
"data-zoomable": 'True',
"text_line": 'teest'
};
我正在解析的脚本来自https://www.brilliantearth.com/Petite-Twisted-Vine-Diamond-Ring-White-Gold-BE1D54-3821855/
如果您像我一样发现正则表达式标志令人困惑且难以记忆,请使用
"not semicolon" 表达式而不是点
re.findall(r"product_images\['top_lg'] = [^;]*;", txt)
注。否则你可以按照蒂埃里的建议添加一个标志,尽管你还需要在 * 之后添加一个 'non-gready modifier' ?
以表明你对第一个分号而不是最后一个分号感兴趣。
我正在尝试从 Javascript 代码中查找并提取 属性 对象的 属性 赋值,使用 BeautifulSoup 提取。我试过关注
re.findall(r"product_images\['top_lg'] = .*;", txt)
不幸的是,它没有从我下面的文本中提取任何内容。
product_images['top_lg'] = {
"tn": '//image.test.com/media/cache/04/0a/040a1e61f5edc387d8c8e40d3ea0e0ca.jpg',
"md": '//image.test.com/media/cache/b7/f3/b7f3cb1da267d7e8ac0412bdc522c862.jpg',
"lg": '//image.test.com/media/shape_images/011f7f24ae4cbbef191cff1a711df9e1_a3c9ca71b7d85d87085955f8d1c4bfc3_0_.jpg',
"alt": 'test ',
"data-zoomable": 'True',
"text_line": 'teest'
};
我正在解析的脚本来自https://www.brilliantearth.com/Petite-Twisted-Vine-Diamond-Ring-White-Gold-BE1D54-3821855/
如果您像我一样发现正则表达式标志令人困惑且难以记忆,请使用 "not semicolon" 表达式而不是点
re.findall(r"product_images\['top_lg'] = [^;]*;", txt)
注。否则你可以按照蒂埃里的建议添加一个标志,尽管你还需要在 * 之后添加一个 'non-gready modifier' ?
以表明你对第一个分号而不是最后一个分号感兴趣。