python+selenium 活动页面监控(获取活动页面商品链接,商品名称价格,自动加购核算总价)

python+selenium 活动页面监控(获取活动页面商品链接,商品名称价格,自动加购核算总价),第1张

概述fromseleniumimportwebdriverimporttimeimportjsonwb=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&pva
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 活动页面监控(获取活动页面商品链接,商品名称价格,自动加购核算总价)所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1189125.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存