HTML篇

一、常见元素类型:

  1. input 输入域  type

  1. button

  1. select

  1. ul列表

  1. a 超链接

  1. image图片

  1. table表格

  1. form表达单

  1. dicv块元素 ,页面布局

  1. 文本 p段落 span短文本  同行

二、元素定位

原则:哪个变得少用哪个元素定位方法,越简单越好,方便后期好维护脚本(比如:有个元素套了好几层,点哪个效果都是一样的,那就用最外层的)

  1. xpath:

a. /表示路径

    根节点/bookstore/book/title

b.//递归路径

c.[]谓语  表示xx条件

/bookstore/book[1] ---- 数字---索引

/bookstore/book[@cover] --- 属性前加@

/bookstore/book[@category='web']

/bookstore/book[@category='web' and @cover] ----谓语里面可加and or not

/bookstore/book[not@category='web']

//title[text()='Learning XML']  -----text()要加括号

/bookstore/book/title[text()='Learning XML']/../      -----回到上层

/bookstore/book/[title='Learning XML']

//book//*/text()    -----选取book下所有后代节点的text值,用到了通配符*

//book[count(author)=1 and @category='web']/year   --选取 单个作者 且 分类是web的书的出版年份值

//book[count(author)=1 and price >30]/@category   ---选取 单个作者 且 定价大于30的书的分类签

//book[count(author)>1 and contains(title, 'X')]/price   ----选取 多个作者 且 标题是以X开头的 书的定价

//book[@category='web' and not(contains(author, 'James'))]/title----选取 分类是web 且作者不包括James的所有书的标题

//book[count(author)>1 and stars-with(title,'X')]/price -----选取多个作者 且标题是以x开头的书的定价

可以加函数:  count、contains、stars-with等

总结:

查询对象,层层找

一个元素是一个单独的个体,它有属性,有内容值

contains(属性名或节点名,文本值)

  1. 定位:

  1. 操作中定位:

li =driver.find_elements_by(xpath,"//ul[@class='tab-head clearfix']/li")

for l in li:

li.click()

time.sleep(1)

prices = driver.find_elements_by(xpath,'//div[@class="tab-body"]//dl[contains@style,'display:block']')

for p in prices:

    print(p.text)

注意:切换页面后查看元素时,检查下style属性是不是'display:none',如果有则选择block值才可取到值

  1. 翻页: 思路:找下一个元素是否可被点击,如果不能点击则到了最后一页

  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿宝999

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值