使用selenium各种定位的时候,是不是经常遇到定位难的问题,现在推荐大家使用谷歌浏览器的神器,帮我们获取想要的定位元素,今天主要介绍xpath,其它方式类似!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
打开谷歌浏览器开发者模式文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
选择元素这栏,然后光标定位到我们想要获取的内容处文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
然后谷歌会自动定位到我们所点数据的元素位置文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
接下来就是见证奇迹的时刻了文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
右击鼠标-Copy - Copy Xpath文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
然后粘贴复制的信息:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
//*[@id="grid-count-area"]/li[1]/span
完美,将改内容粘贴到我们的代码中:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
mapStr = driver.find_element_by_xpath("//*[@id='grid-count-area']/li[1]/span").text print("mapStr:",mapStr)
文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html
完美的获取到数据!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html