在蟒蛇捕獲標籤之間的狀態我想捕捉字WORD
一句This is what I want.
在以下格式:使用XPath
<div id="message1">
<div class="message2">
<strong>WORD</strong> This is what I want.<br/>
</div>
</div>
我想的是:
import requests
from lxml import html
cont=session.get('http://mywebsite.com').content
tree=html.fromstring(cont)
word=tree.xpath('//div[@class="message2"]/strong')
sentence=tree.xpath('//div[@class="message2"]/br')
print word
print sentence
什麼也沒有打印爲了我!
我不知道他爲什麼會短語這個問題是我想要的,但說他想要什麼的是在強烈的一個字標籤?所以如果那是他正在尋找的東西,那麼你的答案是正確的。 – PythonIsGreat
回答實際上是錯誤的......無論哪種方式,我現在修復它:) – Leon
它仍然是錯誤的:)雖然數組索引從xpath開始1,他們仍然在python的'0'開始。 – hek2mgl