python-使用splinter打开和登录网页,但需要保存完整的网页
我正在使用splinter获取电子邮件和密码,然后在firefox中打开facebook并登录,可以在下面的代码中看到 这一切都很好,但我正在寻找一种方法来保存网页一旦登录,从周围看splinter不能做到这一点,还看了硒似乎也不能做到这一点。有没有办法做到这一点python-使用splinter打开和登录网页,但需要保存完整的网页,python,facebook,python-2.7,selenium,splinter,Python,Facebook,Python 2.7,Selenium,Splinter,我正在使用splinter获取电子邮件和密码,然后在firefox中打开facebook并登录,可以在下面的代码中看到 这一切都很好,但我正在寻找一种方法来保存网页一旦登录,从周围看splinter不能做到这一点,还看了硒似乎也不能做到这一点。有没有办法做到这一点 from splinter import Browser # takes the email address for the facebook account needed user_email = raw_input("enter
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获取网页内容。可能需要更多的解释才能帮助其他程序员理解代码的工作原理。OP询问如何保存页面。我不认为更改登录按钮的ID会导致这种情况。
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.