0

私はsplinterを使用して電子メールとパスワードを受け取り、次にFirefoxでFacebookを開いてログインします。これは以下のコードで確認できます。

これはすべて正常に機能しますが、ログインしたWebページを保存する方法を探しています.splinterを見てこれを行うことはできません. これを行う方法はありますか?

from splinter import Browser

# takes the email address for the facebook account needed
user_email = raw_input("enter users email address ")

# takes the oassword for the user account needed
user_pass = raw_input("enter users password ")

# loads the firefox broswer
browser= Browser('firefox')

#selects facebook as the website to load in the browser
browser.visit('http://www.facebook.com')

# fills the email field in the facebook login section 
browser.fill('email', user_email)
browser.fill('pass', user_pass)

#selects the login button on the facebook page to log in with details given
button = browser.find_by_id('u_0_d')
button.click()
4

2 に答える 2

1

browser.htmlを使用して Web ページのコンテンツを取得できます。

于 2014-01-29T01:11:40.867 に答える
0
from splinter import Browser

user_email = raw_input("enter users email address ")
user_pass = raw_input("enter users password ")
browser= Browser('firefox')
browser.visit('http://www.facebook.com')

browser.fill('email', user_email)
browser.fill('pass', user_pass)

#Here is what I made a slight change
button = browser.find_by_id('loginbutton')
button.click()

#I didn't find the page saving function for facebook using Splinter but as an alternative I found screenshot feature. 
browser.screenshot()

# This one is working with other websites but for some reason not with facebook.
import urllib2
page = urllib2.urlopen('http://stackoverflow.com')
page_content = page.read()
with open('page_content.html', 'w') as fid:
    fid.write(page_content)

#Hope this helps ;)

*Note:- The Saving directory would be Python directory, temp or Desktop.
于 2014-06-10T16:09:42.887 に答える