0

HTMLデータから特定のタグ間のデータを取得したい。

<ul>    
    <li>
        More consistent tension control and approximation with each pass than with traditional sutures.
        <ul>                    
            <li>Unique anchor designs provide multiple points of fixation along the device, allowing tension on the device to be maintained during closure.<sup><a class="reference_link" href="#22">[22]</a></sup></li>
            <li>Compared to traditional sutures, STRATAFIX™ Devices enable surgeons to easily manage tension and control approximation with each pass.<sup><a class="reference_link" href="#3">[3]</a></sup></li>
        </ul>
    </li>
<ul>

ここでは、<a class="reference_link" href="#3">[3]</a>その値を保存したいからデータを取得したい(eg.3)。

前もって感謝します。

4

4 に答える 4

0

Beautiful Soupモジュールを使用して、pythonを使用してhtmlページを解析できます。

ここにリンクがあります - http://www.crummy.com/software/BeautifulSoup/

これには、従うことができるいくつかのサンプルコードがあります。 http://www.pythonforbeginners.com/python-on-the-web/beautifulsoup-4-python/

于 2013-09-12T10:44:43.097 に答える
0

美しいスープを試してみてください ここにコードがあります

import urllib2
from bs4 import BeautifulSoup
response = urllib2.urlopen('http://www.crummy.com/software/BeautifulSoup/bs4/doc/')
html = response.read()
soup = BeautifulSoup(html_doc)
for link in soup.find_all('a'):
    link1 = link.get('href') 
    print link1

これは、コーディング言語として Python を使用している場合に当てはまります。これにより、ドキュメントに存在するすべてのリンクが取得されます。beatifulsoup ドキュメントのリンクは次のとおりです。

http://www.crummy.com/software/BeautifulSoup/bs4/doc/

于 2013-09-13T13:38:32.440 に答える