2017-12-07 4 views
0

私はHTMLをスクラップし、難しい課題を抱えてbeautifulsoupを学ぼうとしています。 ..私はスクラップにしようとしているHTMLがうまくフォーマットされていないとbeautifulsoupと知識の欠如と私は一種の立ち往生していますPythonでBeautifulSoup

私はスクラップにしようとしていますHTMLだから

*<tr class="unique"> 
        <td>S.N.</td> 
        <td><a href="http://www.nepalstock.com/main/todays_price/index/1/stock-name/desc/" class="icon-asc sorter">Traded Companies</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/transaction/asc/" class="icon-sorter sorter">No. Of Transaction</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/max-price/asc/" class="icon-sorter sorter">Max Price</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/min-price/asc/" class="icon-sorter sorter">Min Price</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/closing-price/asc/" class="icon-sorter sorter">Closing Price</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/total-share/asc/" class="icon-sorter sorter">Traded Shares</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/amount/asc/" class="icon-sorter sorter">Amount</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/previous-closing/asc/" class="icon-sorter sorter">Previous Closing</a></td> 
        <td class="alnright"><a href="http://www.nepalstock.com/main/todays_price/index/1/difference/asc/" class="icon-sorter sorter">Difference Rs.</a></td> 
       </tr> 
       <tr> 
        <td>1</td> 
        <td>Agriculture Development Bank Limited</td> 
        <td class="alnright">47</td> 
        <td class="alnright">437.00</td> 
        <td class="alnright">426.00</td> 
        <td class="alnright">435.00</td> 
        <td class="alnright">9725.00</td> 
        <td class="alnright">4204614.00</td> 
        <td class="alnright">431.00</td> 
        <td class="alnright">4.00&nbsp; 
         <img src="http://www.nepalstock.com/images/increase.gif"> 
        </td> 
       </tr>* 

私が望む結果、以下のようです取得する文字列は、 "農業開発銀行株式会社"です。 ご協力いただきありがとうございます!

+0

あなたのコードとあなたが掻き取ろうとしているURLを載せてください。 –

+0

これはあなたのために 'soup.find_all( 'tr')[1] .find_all( 'td')[1] .text.strip()' –

+0

私はこのURLから掻き集めようとしています。すべての商社がリストアップします。 nepalstock.com/todaysprice。 - bijay subedi @SagunShrestha –

答えて

0

あなたが探しているものを一般的に尋ねると、より正確にお手伝いできます。あなたのこの必要性を満たすコードはここにあります。

from bs4 import BeautifulSoup 
html_doc = """ 
Your HTML code 
""" 
soup = BeautifulSoup(html_doc, 'html.parser') 
soup.find("td", text="Agriculture Development Bank Limited").text 
関連する問題