简体   繁体   English

使用python登录网页并在浏览器中显示结果

[英]login a webpage using python and display the result in the browser

I'm a beginner in python and as a learning project i decided to just make a little script to lunch a webpage and log into it. 我是python的初学者,作为一个学习项目,我决定只制作一个小脚本吃午餐并登录它。 Now after doing lots of googling (got many messy bits and piece of knowlegde) i found out that each website have it own way of handling login requests, and that there was many ways to emulate an instance of a browser to retrieve and post data ( urllib2, selenium, twill and blablabla). 现在,经过大量的谷歌搜索(获得了很多混乱和知识),我发现每个网站都有其处理登录请求的方式,并且有很多方法可以模拟浏览器实例来检索和发布数据( urllib2,硒,斜纹和blablabla)。

So I know it is possible to log in into a website from python ( for a specific site and using a specific way) but I can't seem to display the logged page in a browser. 因此,我知道可以从python登录到网站(针对特定站点并使用特定方式),但是我似乎无法在浏览器中显示登录的页面。

Can anyone help me please ? 有人可以帮我吗?

I think selenium can do this job. 我认为硒可以做到这一点。

code snippet: 代码段:

from selenium import webdriver 
from selenium.common.exceptions import NoSuchElementException 
from selenium.webdriver.common.keys import Keys

browser = webdriver.Firefox() # Get local session of firefox 
browser.get(yoursite) # Load page 
elem = browser.find_element_by_name("email") # Find the query box 
elem.send_keys(email) 

ps = browser.find_element_by_name("password") # Find the query box 
ps.send_keys(passwd + Keys.RETURN)

this piece of code will drive your firefox to open the logged page. 这段代码将驱动您的Firefox打开打开的页面。

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

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