python - 如何使用 python 和 beautifulsoup 解析 script 标签

标签 python beautifulsoup

我正在尝试提取页面上 document.write 函数内的框架标记的属性,如下所示:

<script language="javascript">
.
.
.
document.write('<frame name="nav" src="/nav/index_nav.html" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" border = "no" noresize>');
 if (anchor != "") {
  document.write('<frame name="body" src="http://content.members.fidelity.com/mfl/summary/0,,' + cusip + ',00.html?' + anchor + '" marginwidth="0" marginheight="0" scrolling="auto" frameborder="0" noresize>');
 } else {
  document.write('<frame name="body" src="http://content.members.fidelity.com/mfl/summary/0,,' + cusip + ',00.html" marginwidth="0" marginheight="0" scrolling="auto" frameborder="0" noresize>');
 }
 document.write('</frameset>');


// end hiding -->
</script>

findAll('frame') 方法没有帮助。有没有办法读取frame标签的内容?

我正在使用 python 2.5 和 BeautifulSoup 3.0.8。

我也愿意将 python 3.1 与 BeautifulSoup 3.1 一起使用 只要我能够得到结果。

谢谢

最佳答案

仅靠 BeautifulSoup 是做不到的。 BeautifulSoup 在 HTML 到达浏览器时解析它(在任何重写或 DOM 操作之前),并且它不解析(更不用说执行)Javascript。

在这种特殊情况下,您可能需要使用简单的正则表达式。

关于python - 如何使用 python 和 beautifulsoup 解析 script 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1883273/

相关文章:

python - 使用 fasttext 预训练词向量作为在 tensorflow 脚本中的嵌入

python - 使 BeautifulSoup 荣誉 xml :space ="preserve"

python - 如何用漂亮的汤按标题提取网址?

python - BeautifulSoup 使用循环将多个 div 中的信息抓取到 JSON 中

python - 使用 python bs4 从 onclick 属性获取值

python - 使用 PyYaml 加载 YAML 失败?

python - setup.py sdist 排除子目录中的包

javascript - 从 python 中的标签名称中抓取数据

python - 如何获取网络上文件的真实 URL。 (Python)

python - 如何使用 Paramiko 制作 sudo 命令