BeautifulSoup无法从<script type="text/javascript">中提取信息。
创始人
2024-11-27 17:00:04
0

要从

This is a paragraph.

''' soup = BeautifulSoup(html, 'html.parser') # 使用正则表达式匹配script标签的内容 script_tags = soup.find_all('script', attrs={'type': 'text/javascript'}) for script_tag in script_tags: script_content = script_tag.string if script_content: # 在这里可以对script_content进行处理 print(script_content)

运行以上代码,将输出var data = "Hello, World!";

这里使用find_all方法找到所有