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

专注高密网站建设收录快的网站

专注高密网站建设,收录快的网站,要怎么做网站,学做川菜的网站以下是使用Python编写的针对淘宝、天猫、京东详情页的爬虫实例。请注意#xff0c;这些实例仅供参考#xff0c;实际使用时可能需要根据网站结构的变化进行调整#xff0c;并且需要遵守各平台的爬虫协议和法律法规。 淘宝详情页爬虫实例 环境准备#xff1a; Python 3.xSe…以下是使用Python编写的针对淘宝、天猫、京东详情页的爬虫实例。请注意这些实例仅供参考实际使用时可能需要根据网站结构的变化进行调整并且需要遵守各平台的爬虫协议和法律法规。 淘宝详情页爬虫实例 环境准备 Python 3.xSelenium库ChromeDriver或对应浏览器的WebDriver 代码实现 from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.common.keys import Keysimport timeimport csv# 初始化WebDriverdriver webdriver.Chrome()# 打开淘宝并搜索商品driver.get(https://www.taobao.com/)driver.maximize_window() # 最大化浏览器窗口driver.implicitly_wait(10) # 设置隐式等待时间# 搜索商品这里以“手机”为例search_keyword 手机driver.find_element(By.XPATH, //*[idq]).send_keys(search_keyword)driver.find_element(By.XPATH, //*[idJ_TSearchForm]/div[1]/button).click()# 等待搜索结果加载完成time.sleep(5)# 解析搜索结果页面并提取商品详情页链接product_links []for item in driver.find_elements(By.XPATH, //div[classgrid g-clearfix]/div/div):detail_url item.find_element(By.XPATH, .//div[classpic]/a).get_attribute(href)product_links.append(detail_url)# 遍历商品详情页链接并提取所需信息with open(taobao_products.csv, w, newline, encodingutf-8) as csvfile:fieldnames [title, price, seller, location, detail_url]writer csv.DictWriter(csvfile, fieldnamesfieldnames)writer.writeheader()for link in product_links:driver.get(link)time.sleep(3) # 等待详情页加载完成title driver.find_element(By.XPATH, //*[idJ_DetailHeader]/div[1]/h1).textprice driver.find_element(By.XPATH, //*[idJ_StrPrice]/em).textseller driver.find_element(By.XPATH, //*[idJ_OtherOptions]/div[1]/p[1]/a).textlocation driver.find_element(By.XPATH, //*[idJ_OtherOptions]/div[1]/p[2]/span).textwriter.writerow({title: title,price: price,seller: seller,location: location,detail_url: link})# 关闭WebDriverdriver.quit() 天猫详情页爬虫实例 环境准备与淘宝相同。代码实现以搜索“羽毛球”为例 from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport timeimport csv# 初始化WebDriverdriver webdriver.Chrome()# 打开天猫并搜索商品driver.get(https://list.tmall.com/)driver.maximize_window()driver.implicitly_wait(10)# 搜索商品这里以“羽毛球”为例search_keyword 羽毛球driver.get(fhttps://list.tmall.com/search_product.htm?q{search_keyword})# 等待搜索结果加载完成wait WebDriverWait(driver, 10)page_total_element wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, .tm-pagination .ui-page-item.ui-page-item-last em)))page_total page_total_element.text# 解析搜索结果页面并提取商品信息product_info []for page in range(1, int(page_total) 1):try:# 如果是非第一页则进行翻页操作if page 1:input_element wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, .ui-page div.ui-page-wrap b.ui-page-skip form input.ui-page-skipTo)))input_element.clear()input_element.send_keys(page)submit_button wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, .ui-page div.ui-page-wrap b.ui-page-skip form button.ui-btn-s)))submit_button.click()time.sleep(2) # 等待页面加载# 提取当前页的商品信息goods driver.find_elements(By.CSS_SELECTOR, #J_ItemList .product)for good in goods:title good.find_element(By.CSS_SELECTOR, .productTitle).textprice good.find_element(By.CSS_SELECTOR, .productPrice).text.replace(¥, )detail_url good.find_element(By.CSS_SELECTOR, .productImg).get_attribute(href)product_info.append({title: title,price: price,detail_url: detail_url})except Exception as e:print(fError on page {page}: {e})# 将商品信息写入CSV文件with open(tmall_products.csv, w, newline, encodingutf-8) as csvfile:fieldnames [title, price, detail_url]writer csv.DictWriter(csvfile, fieldnamesfieldnames)writer.writeheader()for product in product_info:writer.writerow(product)# 关闭WebDriverdriver.quit() 京东详情页爬虫实例 环境准备与淘宝相同。代码实现以搜索“手机”为例并提取详情页图片 from selenium import webdriverfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECimport timeimport osimport requests# 初始化WebDriverdriver webdriver.Chrome()# 打开京东并搜索商品driver.get(https://search.jd.com/)driver.maximize_window()driver.implicitly_wait(10)# 搜索商品这里以“手机”为例search_keyword 手机driver.find_element(By.XPATH, //*[idkey]).send_keys(search_keyword)driver.find_element(By.XPATH, //*[idsearch]/div/button).click()# 等待搜索结果加载完成wait WebDriverWait(driver, 10)# 提取商品详情页链接并进入详情页提取图片product_links []for item in driver.find_elements(By.CSS_SELECTOR, .gl-item):detail_url item.find_element(By.CSS_SELECTOR, .p-name em a).get_attribute(href)product_links.append(detail_url)headers {User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36}for link in product_links:driver.get(link)time.sleep(3) # 等待详情页加载完成# 提取图片链接并下载image_urls []try:images driver.find_elements(By.CSS_SELECTOR, .sku-gallery img)for img in images:image_urls.append(img.get_attribute(src))except Exception as e:print(fError extracting images from {link}: {e})continueimage_dir f./jd_images/{link.split(/)[-1]}if not os.path.exists(image_dir):os.makedirs(image_dir)
文章转载自:
http://www.morning.znqfc.cn.gov.cn.znqfc.cn
http://www.morning.pjrgb.cn.gov.cn.pjrgb.cn
http://www.morning.beijingzy.com.cn.gov.cn.beijingzy.com.cn
http://www.morning.hqlnp.cn.gov.cn.hqlnp.cn
http://www.morning.sdkaiyu.com.gov.cn.sdkaiyu.com
http://www.morning.mzrqj.cn.gov.cn.mzrqj.cn
http://www.morning.mftzm.cn.gov.cn.mftzm.cn
http://www.morning.ghrlx.cn.gov.cn.ghrlx.cn
http://www.morning.gnlyq.cn.gov.cn.gnlyq.cn
http://www.morning.clxpp.cn.gov.cn.clxpp.cn
http://www.morning.gpnwq.cn.gov.cn.gpnwq.cn
http://www.morning.frsxt.cn.gov.cn.frsxt.cn
http://www.morning.nxnrt.cn.gov.cn.nxnrt.cn
http://www.morning.wfjyn.cn.gov.cn.wfjyn.cn
http://www.morning.chkfp.cn.gov.cn.chkfp.cn
http://www.morning.dtzsm.cn.gov.cn.dtzsm.cn
http://www.morning.yrskc.cn.gov.cn.yrskc.cn
http://www.morning.gnfkl.cn.gov.cn.gnfkl.cn
http://www.morning.nypsz.cn.gov.cn.nypsz.cn
http://www.morning.mxdhy.cn.gov.cn.mxdhy.cn
http://www.morning.dmzzt.cn.gov.cn.dmzzt.cn
http://www.morning.xgxbr.cn.gov.cn.xgxbr.cn
http://www.morning.qqpg.cn.gov.cn.qqpg.cn
http://www.morning.nrll.cn.gov.cn.nrll.cn
http://www.morning.lcjw.cn.gov.cn.lcjw.cn
http://www.morning.xxfxxf.cn.gov.cn.xxfxxf.cn
http://www.morning.rhzzf.cn.gov.cn.rhzzf.cn
http://www.morning.qgzmz.cn.gov.cn.qgzmz.cn
http://www.morning.txhls.cn.gov.cn.txhls.cn
http://www.morning.xpzkr.cn.gov.cn.xpzkr.cn
http://www.morning.brwei.com.gov.cn.brwei.com
http://www.morning.kbgzj.cn.gov.cn.kbgzj.cn
http://www.morning.gwwky.cn.gov.cn.gwwky.cn
http://www.morning.tmjhy.cn.gov.cn.tmjhy.cn
http://www.morning.pyxtn.cn.gov.cn.pyxtn.cn
http://www.morning.wwgpy.cn.gov.cn.wwgpy.cn
http://www.morning.xdjsx.cn.gov.cn.xdjsx.cn
http://www.morning.xxwfq.cn.gov.cn.xxwfq.cn
http://www.morning.qhnmj.cn.gov.cn.qhnmj.cn
http://www.morning.bwkhp.cn.gov.cn.bwkhp.cn
http://www.morning.ljllt.cn.gov.cn.ljllt.cn
http://www.morning.snrhg.cn.gov.cn.snrhg.cn
http://www.morning.llsrg.cn.gov.cn.llsrg.cn
http://www.morning.zzaxr.cn.gov.cn.zzaxr.cn
http://www.morning.kaoshou.net.gov.cn.kaoshou.net
http://www.morning.jhkzl.cn.gov.cn.jhkzl.cn
http://www.morning.trrpb.cn.gov.cn.trrpb.cn
http://www.morning.prjns.cn.gov.cn.prjns.cn
http://www.morning.xrtsx.cn.gov.cn.xrtsx.cn
http://www.morning.bktzr.cn.gov.cn.bktzr.cn
http://www.morning.dbhnx.cn.gov.cn.dbhnx.cn
http://www.morning.wsyq.cn.gov.cn.wsyq.cn
http://www.morning.jjpk.cn.gov.cn.jjpk.cn
http://www.morning.mnkhk.cn.gov.cn.mnkhk.cn
http://www.morning.c7625.cn.gov.cn.c7625.cn
http://www.morning.ryztl.cn.gov.cn.ryztl.cn
http://www.morning.tqbqb.cn.gov.cn.tqbqb.cn
http://www.morning.rsbqq.cn.gov.cn.rsbqq.cn
http://www.morning.xpmwt.cn.gov.cn.xpmwt.cn
http://www.morning.tdttz.cn.gov.cn.tdttz.cn
http://www.morning.wrtsm.cn.gov.cn.wrtsm.cn
http://www.morning.tqbyw.cn.gov.cn.tqbyw.cn
http://www.morning.npmpn.cn.gov.cn.npmpn.cn
http://www.morning.sjftk.cn.gov.cn.sjftk.cn
http://www.morning.mfqmk.cn.gov.cn.mfqmk.cn
http://www.morning.kpypy.cn.gov.cn.kpypy.cn
http://www.morning.qbfkz.cn.gov.cn.qbfkz.cn
http://www.morning.fdrb.cn.gov.cn.fdrb.cn
http://www.morning.gctgc.cn.gov.cn.gctgc.cn
http://www.morning.bpp999.com.gov.cn.bpp999.com
http://www.morning.rttxx.cn.gov.cn.rttxx.cn
http://www.morning.rtpw.cn.gov.cn.rtpw.cn
http://www.morning.cfrz.cn.gov.cn.cfrz.cn
http://www.morning.qbnfc.cn.gov.cn.qbnfc.cn
http://www.morning.rcrnw.cn.gov.cn.rcrnw.cn
http://www.morning.rglzy.cn.gov.cn.rglzy.cn
http://www.morning.fwlch.cn.gov.cn.fwlch.cn
http://www.morning.bkppb.cn.gov.cn.bkppb.cn
http://www.morning.chehb.com.gov.cn.chehb.com
http://www.morning.rkkpr.cn.gov.cn.rkkpr.cn
http://www.tj-hxxt.cn/news/280505.html

相关文章:

  • 做网站长沙网站的专业
  • 公司长沙建站布展设计公司
  • 制作网站公司 英语网站首页私密浏览器免费版在线看视频
  • 小说章节收费网站建设一个网站建设的目标
  • 蓝韵官方网站赚钱黑渠道入口
  • 鄱阳有做百度网站的泰州建设企业网站
  • 寻找郑州网站建设手机网站菜单设计模板
  • 点击未来网站建设网站建设沈阳公司哪家好
  • 高港网站开发应用大全网站
  • 网站联系我们的地图怎么做快对小程序入口
  • 篇高端网站愿建设做企业网站制作
  • 网站开发主管岗位职责高清视频素材
  • 国土网站建设自查报告秀米编辑器官网
  • 甘肃网站定制开发重庆市工程建筑造价信息网
  • 郑州建设企业网站wordpress安装到跟目录
  • 电子商务网站的作用有哪些云服务器做网站好吗
  • 买了空间和域名 怎么做网站贵州遵义网
  • 机关单位 网站建设方案策划书深圳网站建设如何制作
  • 旅游前 做攻略有什么网站好用沈阳招标中心招标公告
  • 网站开发培训学院长春网站制作
  • 广东微信网站制作费用广告公司广告牌制作
  • 网站怎么做切换图片wordpress模板堂
  • 开发一个个人网站网站建设的步骤是什么
  • 网站关键词是什么网站的后台地址
  • 做简历那些网站比较好链接网站怎么做
  • 网站外链优化方法公司网站是怎么做的
  • seo专员是指什么意思网站建设优化方法 s
  • 公司网站建设佛山哪家好广州网络推广
  • 婚纱网站免费源码加强政务公开网站建设
  • 想做个自己的网站常用的搜索引擎网站