当前位置:首页 > Python教程 > python技巧

【Python】获取翻页之后的各页面中的属性值。

如何获取翻页之后的页面中的html标签中的属性值?

技术分享图片

 

             1
            #
             coding=utf-8
             2
            from selenium import webdriver
 3if__name__=="__main__":
 4     n=0 #设置n的初始值
 5     driver = webdriver.Chrome()
 6     driver.get("https://www.lol5s.com/tv/20.html")
 7while n<5: #翻5页
 8         n = n + 1
 9print(您当前所在第%d页 % n)
10         lists=driver.find_element_by_xpath(/html/body/div[3]/div[3]/ul).find_elements_by_tag_name("a") #每页的xpath都是一样的,所以这里取一样的即可11print(lists)
12for list in lists:
13             href = list.get_attribute("href")
14             title = list.get_attribute(title)
15print(href)
16print(title)
17         driver.find_element_by_link_text(u"下一页").click() #通过翻页操作跳到下一页

 

原文:https://www.cnblogs.com/zhuzhubaoya/p/9281382.html


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!