PyCharm+selenium + webdriver +Chrome操作

PyCharm+selenium安装:链接: https://pan.baidu.com/s/1YQZAGb63qXBXboCui16h3A 提取码: cup2

selenium的安装

方案一:
dos_pip过程中过程中:pip可能会出现的错误
1:Read timeed out:换成:pip --default-timeout=500 install XXX
2:在升级过程中拒绝访问,权限问题:加上–userpip install --user --upgrade pip
3:cannot install :删除Lib\site-packages\XXX.egg_info
方案二:
PyCharm_安装
File—>Settings–>Project Interpreter–>找右边栏中的±->搜索–>install
错误:read time out
解决:点击Manage Repositoties–>删除之前的url–>添加新的镜像url
1:http://mirrors.aliyun.com/pypi/simple/
2:https://pypi.mirrors.ustc.edu.cn/simple/
3:http://pypi.douban.com/simple/
4:https://pypi.tuna.tsinghua.edu.cn/simple/
5:http://pypi.mirrors.ustc.edu.cn/simple/
然后再安装插件就ok

webdriver的安装

复制网址到Chrome :http://chromedriver.storage.googleapis.com/index.html
点击LATEST_RELEASE–>找到对应版本安装。
注意:一定要放到可访问文件中

然后就可以连接操作Chrome了。

简单登录微博:

from selenium import webdriver
from configparser import ConfigParser
wd = webdriver.Chrome()
wd.implicitly_wait(10)
# 设置窗口大小
wd.set_window_size(1200, 1000)
wd.get('http://www.weibo.com/')
wd.find_element_by_id('loginname').send_keys('1123213214')
# 写配置文件
wd.find_element_by_xpath("//div[@class='info_list password']/div/input").send_keys('pwd')
wd.find_element_by_xpath("//div[@class='info_list login_btn']/a").click()

id和xpath的查找:在网址中右击—>检查.找到对应的id或者xpath,有id用id,没id用xpath。

关于密码的问题:自己登录的时候密码直接输入在pwd那个地方就可以,但是如果要自己设置的话,就要配置ini专门存放密码,总不能自己的实训的时候把密码暴漏给别人吧。

发布了61 篇原创文章 · 获赞 114 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_45822638/article/details/104876637