出版物の Web ページを解析して著者を抽出する Web スクレーパーを作成しようとしています。Web ページの骨格構造は次のとおりです。
<html>
<body>
<div id="container">
<div id="contents">
<table>
<tbody>
<tr>
<td class="author">####I want whatever is located here ###</td>
</tr>
</tbody>
</table>
</div>
</div>
</body>
</html>
これまでのところ、このタスクを達成するために BeautifulSoup と lxml を使用しようとしましたが、2 つの div タグと td タグには属性があるため、どのように処理すればよいかわかりません。これに加えて、BeautifulSoup と lxml のどちらに頼るべきか、あるいは両方の組み合わせに頼るべきかわかりません。私は何をすべきか?
現時点では、私のコードは以下のようになります。
import re
import urllib2,sys
import lxml
from lxml import etree
from lxml.html.soupparser import fromstring
from lxml.etree import tostring
from lxml.cssselect import CSSSelector
from BeautifulSoup import BeautifulSoup, NavigableString
address='http://www.example.com/'
html = urllib2.urlopen(address).read()
soup = BeautifulSoup(html)
html=soup.prettify()
html=html.replace(' ', ' ')
html=html.replace('í','í')
root=fromstring(html)
多くの import ステートメントが冗長である可能性があることは認識していますが、現在持っているものをより多くのソース ファイルにコピーしただけです。
編集:私はこれを明確にしていないと思いますが、ページにスクレイピングしたいタグが複数あります。