用python美化

2024-10-02 02:34:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力学习beautifulsoup来废弃HTML,并有一个困难的挑战。我试图取消的HTML不是很好的格式和与美丽的缺乏知识,我是一种卡住

我尝试废弃的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>*

所以我想得到的结果是字符串“农业发展银行有限公司”。 提前感谢您的帮助


Tags: comhttpindexmainwwwpriceclasstd
1条回答
网友
1楼 · 发布于 2024-10-02 02:34:11

如果你总的问它你在找什么,它能更准确地帮助你。下面是满足您这个需要的代码

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

相关问题 更多 >

    热门问题