from selenium import webdriverimport timeimport Jsonwb = webdriver.Chrome()wb.maximize_window()wb.implicitly_wait(10)url = 'https://subject.autohome.com.cn/carservice/2019/12/hnzt/?refpage=18518&exl_pvID=6833672&exl_hdID=18518&pvareaID=3281150'wb.get(url)# 提前add了一份cookie,直接打开保存的cookie文件with open('D:\qichecookies.txt', 'r', enCoding='utf8') as f: Listcookies = Json.loads(f.read())for cookie in Listcookies: wb.add_cookie(cookie)# 读取完cookie刷新页面wb.refresh()# 找到所有商品的链接link = wb.find_elements_by_CSS_selector('.w>li>a')links = []for i in link: if 'https' in i.get_attribute('href'): links.append(i.get_attribute('href'))print(links)text = []price = []# 商品详情取标题,价格,加购物车for i in links: try: wb.get(i) time.sleep(5) text.append(wb.find_element_by_CSS_selector('#detailheader>h1').text) price.append(wb.find_element_by_ID('price').text) try: wb.find_element_by_name('normal').click() wb.find_element_by_ID('addCart').click() time.sleep(3) except: print(wb.find_element_by_CSS_selector('#detailheader>h1').text,'暂不支持销售') except Exception as e: print(e)print(text)print(price)# 购物车页面取商品总价wb.get(wb.find_element_by_class_name('nav-right').get_attribute('href'))time.sleep(3)total = wb.find_element_by_ID('allPrice')print('商品总价:', total.text)
总结
以上是内存溢出为你收集整理的python+selenium 活动页面监控(获取活动页面商品链接,商品名称价格,自动加购核算总价)全部内容,希望文章能够帮你解决python+selenium 活动页面监控(获取活动页面商品链接,商品名称价格,自动加购核算总价)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)