繁体   English   中英

python-使用splinter打开和登录网页,但需要保存完整的网页

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

我正在使用splinter接收电子邮件和密码,然后在firefox中打开facebook并登录,这可以在下面的代码中看到。

这一切都很好,但是我正在寻找一种方法来保存网页,因为它无法从四面八方登录,也无法做到这一点,而硒也似乎也无法做到这一点。 有什么办法吗?

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.

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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