Python requests可以模拟登录需要身份信息的网站吗,pythonrequests,我用python的req
Python requests可以模拟登录需要身份信息的网站吗,pythonrequests,我用python的req
我用python的requests的库实现了模拟登录人人,但是如何用浏览器打开这个自动登录后的网页呢?webbrowser打开session返回的url不管用......初入python,求教!
使用python的这个库吧 selenium ,这个强大,构建自动化测试都毫无压力
如果想用浏览器自动打开的话,可以尝试一下楼上兄台的建议:
Selenium是基于webdriver的著名自动化测试工具,可以轻松搞定楼主的问题。
比如我下面这段给出的example,可以完成你的需求,模拟登录人人
# -*- coding:utf-8 -*-from selenium import webdriverfrom selenium.webdriver.support.wait import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.common.exceptions import NoSuchElementExceptionfrom selenium.webdriver.common.by import Bywd = webdriver.Firefox()wd.get("http://www.renren.com")wd.maximize_window()try: """这段可以查看selenium的源码,属于smart wait""" email = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'email')),message=u'元素加载超时!') email.send_keys("*** 你的账号 ***") passwd = WebDriverWait(wd,timeout=10).until(EC.presence_of_element_located((By.ID,'password')),message=u'元素加载超时!') passwd.send_keys("*** 你的密码 ***") wd.find_element_by_id("login").click() #点击登录except NoSuchElementException as e: print e.message
感谢阅读。
编橙之家文章,
相关内容
- python语言里函数作用域unBoundError错误问题请教,python
- Python多线程读取文件进程读取到内容不全如何破,pyt
- Python有支持url发送指令控制服务器的方法吗,pythonurl
- 想使用redis和gevent完成实时消息系统求思路,redisgeven
- 要用python获取MySQL连接器如何写,pythonmysql,从MySQL官网上
- cookbook书中关于装饰器的源码里,这个参数是怎么传递的
- Python解决算法复杂度问题求助,python问题求助,问题是
- Python tornado分页合并展示问题,pythontornado,需要在用户输
- Python3二进制转化成字符串有什么好的解决办法吗,py
- python报错信息type 'exceptions.AttributeError'是什么意思,,
评论关闭