用靓汤提取文本

2024-03-29 15:46:04 发布

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

我想用bs4从这个html中提取文本,我是新手,似乎不能得到它,任何帮助非常感谢。在

<div class="results">
            <span class="toggle" ng-click="display.toggleConfig()">{{display.configText}}</span>


            <p ng-hide="insecure">It would take <span ng-show="config.calculationsOriginal">a desktop PC</span> about <span class="main">{{time}}</span> to crack your password</p>
            <a class="tweet-me" ng-hide="insecure" href="http://twitter.com/home/?status=It would take a desktop PC about {{time}} to crack my password!%0d%0dhttp://hsim.pw">[Tweet Result]</a>

            <p ng-show="insecure">Your password would be cracked almost <span class="main">Instantly</span></p>
            <a class="tweet-me" ng-show="insecure" href="http://twitter.com/home/?status=My password would be cracked almost instantly!%0d%0dhttp://hsim.pw">[Tweet Result]</a>

            <span class="toggle" ng-click="display.toggleDetails()">{{display.detailsText}}</span>
        </div>

        <ul ng-show="display.details">
            <li><strong>Length:</strong> {{length}} characters</li>
            <li><strong>Character Combinations:</strong> {{characters}}</li>
            <li><strong>Calculations Per Second:</strong> {{calcsPerSecond}}</li>
            <li><strong>Possible Combinations:</strong> {{possibleCombinations}}</li>
        </ul>

        <ul ng-show="checks">
            <li ng-repeat="check in checks" class="{{check.type}}">
                <h2 ng-bind-html-unsafe="check.title"></h2>
                <p ng-bind-html-unsafe="check.wording"></p>
            </li>
        </ul>

我尝试了:

^{pr2}$

Tags: divhtmlcheckshowdisplaypasswordling
1条回答
网友
1楼 · 发布于 2024-03-29 15:46:04

时间在html中的实际位置有点不清楚,但它看起来像是在<span>和{}中。其中有两种,可以很容易地提取:

for x in soup.findAll("span",{"class":"main"}):
    print x.text

给出:

^{pr2}$

如果要获取对象中的所有文本,请尝试:

soup.get_text()

它将递归地从对象及其子对象中提取所有文本。在

相关问题 更多 >