输入到网页并检索输出

时间:2014-11-04 16:35:50

标签: python

我正在尝试输入密码" howsecureismypassword"网站并使用webscraping检索输出..这是可能的。这是网页上的html,下面是我到目前为止的代码,任何帮助都将不胜感激。

<div role="main">
    <div class="input">
        <input type="password" id="password" ng-model="password" ng-change="passwordChange()" placeholder="Enter Password" class="password" autofocus>
    </div>

    <div class="phishing" ng-hide="password">
        <p>This site could be stealing your password... it's not, but it easily <em>could</em> be.<br />Be careful where you type your password.</p>
    </div>

    <div ng-show="password">
        <ul ng-show="display.config">
            <li>
                <label><input type="checkbox" ng-model="config.namedNumbers" ng-change="config.changeNamedNumbers()" />Use Named Numbers</label>
            </li>
            <li>
                <label>Calculations per second</label>
                <input type="text" ng-model="config.calculations" ng-change="config.changeCalculations()" />
            </li>
        </ul>

        <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>
# Program to access a web page using httplib2
from httplib2 import Http
from urllib.parse import urlencode

# Create a web object
h = Http()

# set the url of the webpage
url = 'https://howsecureismypassword.net/'

password=input('enter')

# Create a data dictionary
data = {'placeholder' : password}

# encode the dictionary
web_data = urlencode(data)

# Connect to the local web server 192.168.26.10
response, content = h.request(url, 'POST', web_data)

if response.status == 200:
   # Display the contents of the web page returned
   text_content = content.decode()
   print('Contents:')
   print(text_content)

   # Turn it into "Beautiful Soup"
   from bs4 import BeautifulSoup
   soup = BeautifulSoup(content)
   print(soup.get_text())
else:
   print('Error accesing web page')

1 个答案:

答案 0 :(得分:0)

我会使用splinter。 BeautifulSoup适用于抓取,而不适用于与页面交互。以下是分裂器的示例:


    from splinter import Browser
with Browser() as browser: # Visit URL url = "http://www.google.com" browser.visit(url) browser.fill('q', 'splinter - python acceptance testing for web applications') # Find and click the 'search' button button = browser.find_by_name('btnG') # Interact with elements button.click() if browser.is_text_present('splinter.cobrateam.info'): print "Yes, the official website was found!" else: print "No, it wasn't found... We need to improve our SEO techniques"

你可以根据自己的需要调整类似的东西。