- 下载插件报Could not fetch URL https://pypi.org/simple/pywinauto/: There was a problem 解决方法
- 使用国内镜像下载
现在使用的是豆瓣的镜像下载的pandas 插件pip3 install --index-url https://pypi.douban.com/simple pandas
国内的其他镜像源
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
阿里云 http://mirrors.aliyun.com/pypi/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣(douban) http://pypi.douban.com/simple/
中国科学技术大学 http://pypi.mirrors.ustc.edu.cn/simple/
- 使用国内镜像下载
-
pip安装一个第三方的库,就一直报错: Could not fetch URL https://pypi.org/simple/xrld/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host=‘pypi.org’, port=443): Max retries exceeded with url: /simple/xrld/ (Caused by SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:833)’),)) - skipping
-
1.第一种尝试方式:直接下载get-pip.py文件,执行命令python get-pip.py 结果是:失败
2.第二种尝试方式:加上–trusted-host 执行 pip install xrld -i https://pypi.org/simple --trusted-host pypi.org 结果是:失败
3.第三种尝试:发现是url的来源的问题,换成了国内的pip源就可以正常安装了,我使用的是:pip install pywinauto -i http://pypi.douban.com/simple --trusted-host pypi.douban.com,结果:Duang!Duang!Duang~成功 - 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/ 中国科学技术大学
-
-
Kivy Unable to get a Window, abort.
-
原因是我缺少一个相应的模块
在命令行窗口使用pip命令安装模块
pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
-
-
xx.whl 文件安装
pip install xx.whl -
Python selenium 使用遇到的问题
-
由父节点定位子节点
最简单的肯定就是由父节点定位子节点了,我们有很多方法可以定位,下面上个例子:
对以下代码:
<html>
<body>
<div id="A">
<!--父节点定位子节点-->
<div id="B">
<div>parent to child</div>
</div>
</div>
</body>
</html>
想要根据
-
串联寻找
driver.find_element_by_id('B').find_element_by_tag_name('div').text -
xpath父子关系寻找
driver.find_element_by_xpath("//div[@id='B']/div").text -
css selector父子关系寻找
driver.find_element_by_css_selector('div#B>div').text -
css selector nth-child
driver.find_element_by_css_selector('div#B div:nth-child(1)').text -
css selector nth-of-type
driver.find_element_by_css_selector('div#B div:nth-of-type(1)').text -
xpath轴 child
driver.find_element_by_xpath("//div[@id='B']/child::div").text
-
-
由子节点定位父节点
由子节点想要定位到父节点就有点难度了,对以下代码:
<html>
<body>
<div id="A">
<!--子节点定位父节点-->
<div>
<div>child to parent
<div>
<div id="C"></div>
</div>
</div>
</div>
</div>
</body>
</html>
我们想要由 C节点 定位其两层父节点的div,示例代码如下:-
.xpath: `.`代表当前节点; '..'代表父节点
driver.find_element_by_xpath("//div[@id='C']/../..").text -
xpath轴 parent
driver.find_element_by_xpath("//div[@id='C']/parent::*/parent::div").text
这里我们有两种办法,第1种是 .. 的形式,就像我们知道的,. 表示当前节点,.. 表示父节点;第2种办法跟上面一样,是xpath轴中的一个:parent,取当前节点的父节点。这里也是css selector的一个痛点,因为css的设计不允许有能够获取父节点的办法(至少目前没有)
-
-
由弟弟节点定位哥哥节点
这是第3、第4种情况,我们这里要定位的是兄弟节点了。如以下源码:
<html>
<body>
<div>
<!--下面两个节点用于兄弟节点定位-->
<div>brother 1</div>
<div id="D"></div>
<div>brother 2</div>
</div>
</body>
</html>
怎么通过 D节点 定位其哥哥节点呢?看代码示例:
-
.xpath,通过父节点获取其哥哥节点
driver.find_element_by_xpath("//div[@id='D']/../div[1]").text -
xpath轴 preceding-sibling
driver.find_element_by_xpath("//div[@id='D']/preceding-sibling::div[1]").text
-
-
由哥哥节点定位弟弟节点
源码与 3 一致,要想通过 D节点 定位其弟弟节点,看代码示例:-
xpath,通过父节点获取其弟弟节点
driver.find_element_by_xpath("//div[@id='D']/../div[3]").text -
xpath轴 following-sibling
driver.find_element_by_xpath("//div[@id='D']/following-sibling::div[1]").text -
xpath轴 following
driver.find_element_by_xpath("//div[@id='D']/following::*").text -
css selector +
driver.find_element_by_css_selector('div#D + div').text -
css selector ~
driver.find_element_by_css_selector('div#D ~ div').text
面三种是用xpath,第一种很好理解,第二种用到了xpath轴:following-sibling,跟preceding-sibling类似,它的作用是获取当前节点的所有同级弟弟节点,同样,1 代表离当前节点最近的一个弟弟节点,数字越大表示离当前节点越远;第三种用到了xpath轴:following,获取到该节点之后所有节点,除了祖先节点(跟preceding方向相反,但因为往下顺序容易读,不容易出错,所以也是可以用来获取弟弟节点的,但也不建议这么使用);第四、第五种,我们用到了css selector,+ 和 ~ 的区别是: + 表示紧跟在当前节点之后的div节点,~ 表示当前节点之后的div节点,如果用find_elements,则可获取到一组div节点。
-
-
-
-