gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 00:00:07 24 4
gpt4 key购买 nike

我正在尝试提取页面上 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com