【Python】獲取翻頁之後的各頁面中的屬性值。
阿新 • • 發佈:2018-07-09
utf-8 通過 .com lol list __name__ n) 圖片 lis
如何獲取翻頁之後的頁面中的html標簽中的屬性值?
1 # coding=utf-8 2 from selenium import webdriver 3 if __name__=="__main__": 4 n=0 #設置n的初始值 5 driver = webdriver.Chrome() 6 driver.get("https://www.lol5s.com/tv/20.html") 7 while n<5: #翻5頁 8 n = n + 1 9 print(‘您當前所在第%d頁‘ % n) 10 lists=driver.find_element_by_xpath(‘/html/body/div[3]/div[3]/ul‘).find_elements_by_tag_name("a") #每頁的xpath都是一樣的,所以這裏取一樣的即可 11 print(lists) 12 for list in lists: 13 href = list.get_attribute("href") 14 title = list.get_attribute(‘title‘) 15 print(href) 16 print(title) 17 driver.find_element_by_link_text(u"下一頁").click() #通過翻頁操作跳到下一頁
【Python】獲取翻頁之後的各頁面中的屬性值。