【发布时间】:2011-03-14 13:47:32
【问题描述】:
我想知道是否可以显示隐藏标签的值。我正在使用 urllib 和 beautifulsoup,但我似乎无法得到我想要的。
我使用的html代码如下:(另存为hiddentry.html)
<html>
<head>
<script type="text/javascript">
//change hidden elem value
function changeValue()
{
document.getElementById('hiddenElem').value = 'hello matey!';
}
//this will verify if i have successfully changed the hiddenElem's value
function printHidden()
{
document.getElementById('displayHere').innerHTML = document.getElementById('hiddenElem').value;
}
</script>
</head>
<body>
<div id="hiddenDiv" style="position: absolute; left: -1500px">
<!--i want to find the value of this element right here-->
<span id="hiddenElem"></span>
</div>
<span id="displayHere"></span>
<script type="text/javascript">
changeValue();
printHidden();
</script>
</body>
</html>
我要打印的是 ID 为 hiddenElem 的元素的值。 为此,我尝试使用 urllib 和 beautifulsoup 组合。我使用的代码是:
from BeautifulSoup import BeautifulSoup
import urllib2
import urllib
mysite = urllib.urlopen("http://localhost/hiddentry.html")
soup = BeautifulSoup(mysite)
print soup.prettify()
print '\n\n'
areUthere = soup.find(id="hiddenElem").find(text=True)
print areUthere
我得到的输出是 None。 有任何想法吗?我正在努力实现的目标有可能吗?
【问题讨论】:
标签: python beautifulsoup urllib