1

我最近询问了一种在 python 中调用 js 函数的方法。人们给了我一些建议,例如使用 js2py 或 pyv8,但问题是它不允许我使用以下 js 命令:

document.getElementById("example");

所以我的问题是:有没有办法从 python 函数调用 js 并允许你使用上面的 js 命令?

提前致谢!

4

1 回答 1

2

如果在python中调用js函数意味着:如何选择具有特定id的节点?,那么你可以使用 BeautifulSoup 来实现它:

from bs4 import BeautifulSoup

html_doc = "<html><head><title></title></head><body><div id='example'></body></html>"

soup = BeautifulSoup(html_doc, 'html.parser')
soup.find(id="example")
于 2016-08-23T14:10:36.303 回答