当前位置: 首页 > news >正文

六安网站建设企业网上购物系统建设

六安网站建设企业,网上购物系统建设,wordpress短代码可视化,网页设计照片数据库连接设置#xff08;表和字段要提前在数据库中建好#xff09; # 数据库中要插入的表 MYSQL_TABLE goods# MySQL 数据库连接配置,根据自己的本地数据库修改 db_config {host: localhost,port: 3306,user: root,password: ma*****6,database: may2024,charset: utf8mb… 数据库连接设置表和字段要提前在数据库中建好 # 数据库中要插入的表 MYSQL_TABLE goods# MySQL 数据库连接配置,根据自己的本地数据库修改 db_config {host: localhost,port: 3306,user: root,password: ma*****6,database: may2024,charset: utf8mb4, }# 创建 MySQL 连接对象 conn pymysql.connect(**db_config) cursor conn.cursor() 全局设置 execl_save zp2024_info.csv 库导入 from pyquery import PyQuery as pq 获取网页信息前提是已进入搜索结果页面 # 获取每一页的商品信息 def get_goods(num):# 获取商品前固定等待2-4秒# random_sleep(2, 4)product_c []clear_mysql_table(MYSQL_TABLE)clear_csv_file(execl_save)driver driver_configure.GetDriver().get_driver()next_page_xpath //*[idsortBarWrap]/div[1]/div[2]/div[2]/div[8]/div/button[2]for n in range(num):html driver.page_sourcedoc pq(html)# 提取所有商品的共同父元素的类选择器items doc(div.PageContent--contentWrap--mep7AEm div.LeftLay--leftWrap--xBQipVc div.LeftLay--leftContent--AMmPNfB div.Content--content--sgSCZ12 div div).items()for item in items:# 定位商品标题title item.find(.Title--title--jCOPvpf span).text()# 定位价格price_int item.find(.Price--priceInt--ZlsSi_M).text()price_float item.find(.Price--priceFloat--h2RR0RK).text()if price_int and price_float:price float(f{price_int}{price_float})else:price 0.0# 定位交易量deal item.find(.Price--realSales--FhTZc7U).text()# 转化万为数字if 万 in deal:deal_n deal.split(万)[0]deal int(10000 * int(deal_n))elif in deal:deal int(deal.split()[0]) # 10人收货/10人付款elif 付款 in deal:deal int(deal.split(人)[0]) # 10人付款# 定位所在地信息location item.find(.Price--procity--_7Vt3mX).text()if in location:province location.split( )[0]city location.split( )[1]else:province locationcity location# 定位店名shop item.find(.ShopInfo--TextAndPic--yH0AZfx a).text()# 定位包邮的位置postText item.find(.SalesPoint--subIconWrapper--s6vanNY span).text()result 1 if 包邮 in postText else 0# 构建商品信息字典product {title: title,price: price,deal: deal,location: location,province: province,city: city,shop: shop,isPostFree: result}product_c.append(product)# print(product)save_to_mysql(product)if n num-1:print(点击下一页至第{}页.format(n 2))baseClass.BaseClass().click_element(next_page_xpath) # 点击 下一页baseClass.BaseClass().scroll_to_end() # 滚动到底部# print(product_c)save_to_csv(product_c)# 在 save_to_mysql 函数中保存数据到 MySQL def save_to_mysql(result):try:sql INSERT INTO {}(price, deal, title, shop, location, province, city, isPostFree) VALUES (%s, %s, %s, %s, %s, %s, %s, %s).format(MYSQL_TABLE)# print(sql语句为: sql)cursor.execute(sql, (result[price], result[deal], result[title], result[shop], result[location], result[province], result[city], result[isPostFree]))conn.commit()# print(存储到MySQL成功: , result)except Exception as e:print(存储到MYsql出错: , result, e)# 清空mysql某个表数据 def clear_mysql_table(table_name):truncate_sql fTRUNCATE TABLE {table_name}cursor.execute(truncate_sql)conn.commit()# close_cursor_conn()# 关闭数据库游标和连接 def close_cursor_conn():cursor.close()conn.close()# 将商品数据保存在csv def save_to_csv(result):# df pd.DataFrame(result, columns[title, price, deal, location, province, city, shop, isPostFree])df pd.DataFrame(result)df.to_csv(execl_save, indexFalse, encodinggbk)# 清空 csv数据 def clear_csv_file(f):with open(f, w) as file:file.truncate(0)部分封装 # 滑动页面到底部def scroll_to_end(self):for i in range(3):self.driver.execute_script(window.scrollTo(0,document.body.scrollHeight))time.sleep(2) # 查找可点击元素并点击def click_element(self, element):try:submit WebDriverWait(self.driver, 15).until(EC.element_to_be_clickable((By.XPATH, element)))submit.click()except TimeoutError:print(翻页超时报错)rand_num random.randint(5, 15) # 设置随机等待的时间time.sleep(rand_num)
http://www.pierceye.com/news/124023/

相关文章:

  • hdwiki做网站罗湖网站建设联系电话
  • 深圳网站建设 利科技wordpress插件 手机版
  • 南通优普网站建设团队课程设计模板
  • 网站建设与维护的选择题浦东新区做网站
  • 做视频网站视频放在哪里网站备案目的
  • 建设部安全事故通报网站怎么更改网站的备案号
  • 重庆网站建设维护网络推广引流方法
  • 精品网站开发分销网站建站
  • 建设一个教程视频网站需要什么资质策划书案例范文
  • 郑州汉狮做网站的大公司海尔网站建设
  • 成都网站制作成都重庆网红景点排名
  • 广西南宁市网站制作公司制作图片的软件加字体
  • 新手搭建网站教程品牌推广费用预算
  • 广州网站设计网站制作竞价托管多少钱
  • 创建企业营销网站包括哪些内容软考高项彻底没用了
  • 企业品牌网站建设方案无锡网站设计多少钱
  • 轻量级网站开发在线旅游网站平台有哪些
  • 怎么用vs做网站推广优化网站排名
  • 免费推广网站软件常宁网站建设常宁网站建设
  • 冀州市网站建设html编辑器安卓版手机版软件
  • 广州专业网站改版方案网站建设要做ui和什么
  • 做网站显示上次登录时间代码h5素材库
  • 比较有名的网站建设公司谷歌网站优化
  • 企业网站改版计划书中国制造网是做什么的
  • 非主营电子商务企业网站有哪些企业网项目建设实践
  • 颍东网站建设手机vi设计公司
  • 林哥seo网络营销seo培训
  • 如何面试网站开发网站制作交易流程
  • 绍兴网站建设冯炳良互联网营销
  • 制作企业网站怎么报价可以做我女朋友吗网站