简体   繁体   中英

python- using splinter to open and login webpage but need to save the complete webpage

I am using splinter to take and email and password then open up facebook in firefox and login which can be seen in the code below.

this all works fine but Im looking for a way to save the webpage once logged in from looking around splinter can not do this also looked at selenium which didnt seem to be able to do it either. is there any ways of doing this?

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()

您可以使用browser.html获取网页内容。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM