<html>
<head>
<script type="text/javascript">
document.write('<a href="http://www.google.com">f*** js</a>');
document.write("f*** js!");
</script>
</head>
<body>
<script type="text/javascript">
document.write('<a href="http://www.google.com">f*** js</a>');
document.write("f*** js!");
</script>
<div><a href="http://www.google.com">f*** js</a></div>
</body>
</html>
私は一つだけのJSによって生成されません取得
In [1]: import lxml.html as H
In [2]: f = open("test.html","r")
In [3]: c = f.read()
In [4]: doc = H.document_fromstring(c)
In [5]: doc.xpath('//a')
Out[5]: [<Element a at a01d17c>]
In [6]: a = doc.xpath('//a')[0]
In [7]: a.getparent()
Out[7]: <Element div at a01d41c>
私は上記のhtmlページ内のすべてのlableのオブジェクトをキャッチするためにXPathを使用したい...〜 Firefoxのxpathチェッカーですべてのlableを見つけることができます!
それをどのように行うには? thx〜!
<html>
<head>
</head>
<body>
<script language="javascript">
function over(){
a.innerHTML="mouse me"
}
function out(){
a.innerHTML="<a href='http://www.google.com'>google</a>"
}
</script>
<body><li id="a"onmouseover="over()" onmouseout="out()">mouse me</li>
</body>
</html>
これは何も役に立ちませんでした。 –
HTMLを解析する前にjsを解析して解釈する必要があります。 http://www.crummy.com/software/BeautifulSoup/を見たことがありますか? –
あなたのjavascriptは、与えられたように意味がありません - ドキュメントの頭にリンクを書いていますか? lxmlの観点からは、document.writeの中の何かは文字列定数であり、解析されるものではありません。 –