#依次点击精品推荐栏目全部商品、GSM手机、双模手机、手机卡
#第一种方法,就是每个页签都点一下,是不是点傻的操作。这是我第一次写出来的。
# driver.find_element_by_xpath('//div[@id="itemBest"]/h2[1]/a[@href="javascript:void(0)"]').click()
# time.sleep(2)
# driver.find_element_by_xpath('//div[@id="itemBest"]/h2[2]/a[@href="javascript:void(0)"]').click()
# time.sleep(2)
# driver.find_element_by_xpath('//div[@id="itemBest"]/h2[3]/a[@href="javascript:void(0)"]').click()
# time.sleep(2)
# driver.find_element_by_xpath('//div[@id="itemBest"]/h2[4]/a[@href="javascript:void(0)"]').click()
# time.sleep(2)
#第二种方法,find_elements_by_xpath,然后遍历列表
li =driver.find_elements_by_xpath('//div[@id="itemBest"]/h2')
# p =[ ]
for ele in li:
ele.click()
time.sleep(2)
# 打印每一个tab页下所有的价格, 一边点一边取价格
price_li = driver.find_elements_by_xpath('//div[@id="show_best_area"]/div/font')
for price in price_li:
print(price.text)
# p.append(price.text)#列表里放所有的价格
# print(p)
driver.quit()
练习5
最新推荐文章于 2019-07-23 11:23:26 发布