import re
from bs4 import BeautifulSoup as bs
html = '''
<script type="text/javascript">app.run({"data":Id":"124330049","stock":83})</script>
'''
soup = bs(html, 'lxml')
scripts = [script.text for script in soup.select('script') if 'app.run({"data":Id"' in script.text]
r = re.compile(r'"stock":(\d+)}')
for script in scripts:
print(r.findall(script))
您可以选择所有的脚本标记,其中包含一个特定的子字符串,然后选择regex
相关问题 更多 >
编程相关推荐