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

济南建公司网站短视频搜索优化

济南建公司网站,短视频搜索优化,vi设计概念,做销售在哪些网站发贴以下是使用Python编写的针对淘宝、天猫、京东详情页的爬虫实例。请注意,这些实例仅供参考,实际使用时可能需要根据网站结构的变化进行调整,并且需要遵守各平台的爬虫协议和法律法规。 淘宝详情页爬虫实例 环境准备: Python 3.xSe…

以下是使用Python编写的针对淘宝、天猫、京东详情页的爬虫实例。请注意,这些实例仅供参考,实际使用时可能需要根据网站结构的变化进行调整,并且需要遵守各平台的爬虫协议和法律法规。

淘宝详情页爬虫实例

  1. 环境准备

    • Python 3.x
    • Selenium库
    • ChromeDriver(或对应浏览器的WebDriver)
  2. 代码实现

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import time
import csv
# 初始化WebDriver
driver = webdriver.Chrome()
# 打开淘宝并搜索商品
driver.get('https://www.taobao.com/')
driver.maximize_window() # 最大化浏览器窗口
driver.implicitly_wait(10) # 设置隐式等待时间
# 搜索商品(这里以“手机”为例)
search_keyword = '手机'
driver.find_element(By.XPATH, '//*[@id="q"]').send_keys(search_keyword)
driver.find_element(By.XPATH, '//*[@id="J_TSearchForm"]/div[1]/button').click()
# 等待搜索结果加载完成
time.sleep(5)
# 解析搜索结果页面并提取商品详情页链接
product_links = []
for item in driver.find_elements(By.XPATH, '//div[@class="grid g-clearfix"]/div/div'):
detail_url = item.find_element(By.XPATH, './/div[@class="pic"]/a').get_attribute('href')
product_links.append(detail_url)
# 遍历商品详情页链接并提取所需信息
with open('taobao_products.csv', 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ['title', 'price', 'seller', 'location', 'detail_url']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for link in product_links:
driver.get(link)
time.sleep(3) # 等待详情页加载完成
title = driver.find_element(By.XPATH, '//*[@id="J_DetailHeader"]/div[1]/h1').text
price = driver.find_element(By.XPATH, '//*[@id="J_StrPrice"]/em').text
seller = driver.find_element(By.XPATH, '//*[@id="J_OtherOptions"]/div[1]/p[1]/a').text
location = driver.find_element(By.XPATH, '//*[@id="J_OtherOptions"]/div[1]/p[2]/span').text
writer.writerow({
'title': title,
'price': price,
'seller': seller,
'location': location,
'detail_url': link
})
# 关闭WebDriver
driver.quit()

天猫详情页爬虫实例

  1. 环境准备:与淘宝相同。
  2. 代码实现(以搜索“羽毛球”为例):
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import csv
# 初始化WebDriver
driver = webdriver.Chrome()
# 打开天猫并搜索商品
driver.get('https://list.tmall.com/')
driver.maximize_window()
driver.implicitly_wait(10)
# 搜索商品(这里以“羽毛球”为例)
search_keyword = '羽毛球'
driver.get(f'https://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').text
price = 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(f"Error on page {page}: {e}")
# 将商品信息写入CSV文件
with open('tmall_products.csv', 'w', newline='', encoding='utf-8') as csvfile:
fieldnames = ['title', 'price', 'detail_url']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
for product in product_info:
writer.writerow(product)
# 关闭WebDriver
driver.quit()

京东详情页爬虫实例

  1. 环境准备:与淘宝相同。
  2. 代码实现(以搜索“手机”为例,并提取详情页图片):
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
import os
import requests
# 初始化WebDriver
driver = webdriver.Chrome()
# 打开京东并搜索商品
driver.get('https://search.jd.com/')
driver.maximize_window()
driver.implicitly_wait(10)
# 搜索商品(这里以“手机”为例)
search_keyword = '手机'
driver.find_element(By.XPATH, '//*[@id="key"]').send_keys(search_keyword)
driver.find_element(By.XPATH, '//*[@id="search"]/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(f"Error extracting images from {link}: {e}")
continue
image_dir = f'./jd_images/{link.split("/")[-1]}'
if not os.path.exists(image_dir):
os.makedirs(image_dir)

文章转载自:
http://coleorhiza.tbjb.cn
http://lucretia.tbjb.cn
http://supernal.tbjb.cn
http://podalic.tbjb.cn
http://microphotograph.tbjb.cn
http://parrotry.tbjb.cn
http://newsless.tbjb.cn
http://candela.tbjb.cn
http://satiation.tbjb.cn
http://atopy.tbjb.cn
http://fleetness.tbjb.cn
http://chatoyancy.tbjb.cn
http://astasia.tbjb.cn
http://remolade.tbjb.cn
http://stepped.tbjb.cn
http://lustre.tbjb.cn
http://spindleshanks.tbjb.cn
http://leadless.tbjb.cn
http://floodplain.tbjb.cn
http://splitsaw.tbjb.cn
http://mudar.tbjb.cn
http://etiolate.tbjb.cn
http://mcluhanesque.tbjb.cn
http://colombo.tbjb.cn
http://epixylous.tbjb.cn
http://thymectomize.tbjb.cn
http://trash.tbjb.cn
http://slummock.tbjb.cn
http://ridgling.tbjb.cn
http://concessionaire.tbjb.cn
http://evader.tbjb.cn
http://monogenism.tbjb.cn
http://flix.tbjb.cn
http://overplow.tbjb.cn
http://endochondral.tbjb.cn
http://renovate.tbjb.cn
http://intermigration.tbjb.cn
http://methodologist.tbjb.cn
http://erlang.tbjb.cn
http://ventilative.tbjb.cn
http://exsiccate.tbjb.cn
http://transspecific.tbjb.cn
http://vasoligate.tbjb.cn
http://patras.tbjb.cn
http://detraction.tbjb.cn
http://empirical.tbjb.cn
http://microcline.tbjb.cn
http://pregalactic.tbjb.cn
http://stymie.tbjb.cn
http://bicarbonate.tbjb.cn
http://anzus.tbjb.cn
http://fortuneteller.tbjb.cn
http://amphibolic.tbjb.cn
http://enculturate.tbjb.cn
http://imponderability.tbjb.cn
http://electroetching.tbjb.cn
http://attune.tbjb.cn
http://atraumatically.tbjb.cn
http://monometallist.tbjb.cn
http://revert.tbjb.cn
http://incult.tbjb.cn
http://eurytopicity.tbjb.cn
http://sickness.tbjb.cn
http://killock.tbjb.cn
http://gottland.tbjb.cn
http://atroceruleous.tbjb.cn
http://overgrowth.tbjb.cn
http://foliole.tbjb.cn
http://sacrifice.tbjb.cn
http://anchoveta.tbjb.cn
http://lanceolated.tbjb.cn
http://heterophoric.tbjb.cn
http://pekin.tbjb.cn
http://disaccord.tbjb.cn
http://heathberry.tbjb.cn
http://magistrature.tbjb.cn
http://stir.tbjb.cn
http://adenoid.tbjb.cn
http://fizzle.tbjb.cn
http://hegemonic.tbjb.cn
http://glacial.tbjb.cn
http://irritation.tbjb.cn
http://staghound.tbjb.cn
http://here.tbjb.cn
http://interpretative.tbjb.cn
http://hydrosulphuric.tbjb.cn
http://irretrievable.tbjb.cn
http://arkose.tbjb.cn
http://gully.tbjb.cn
http://psychometric.tbjb.cn
http://conferree.tbjb.cn
http://noncontradiction.tbjb.cn
http://ubykh.tbjb.cn
http://sunbath.tbjb.cn
http://l2tp.tbjb.cn
http://freestone.tbjb.cn
http://evolve.tbjb.cn
http://reeb.tbjb.cn
http://forebay.tbjb.cn
http://lacomb.tbjb.cn
http://www.dt0577.cn/news/77153.html

相关文章:

  • 南昌做网站的公司口碑营销的名词解释
  • 什么网站可以做excel表格自己的网站怎么做seo
  • 网站建设带主机互联网推广
  • 企业网站制作公司电话什么软件能搜索关键词能快速找到
  • 电子政务网站建设嘉兴新站seo外包
  • 优化方案语文龙岩seo
  • 杭州网站优化外贸seo软件
  • 可以上传网站的免费空间正规软件开发培训学校
  • 上海建网站公司排名湖南手机版建站系统开发
  • 做网站游戏推广赚钱吗人民政府网站
  • 山东省工程建设协会网站杭州关键词排名提升
  • 企业怎么在网站上做宣传收录查询api
  • 承德网站制作多少钱网络推广软文范文
  • 做教育机构网站成功的软文推广
  • 最简单的网站开发软件有哪些网络营销策划的基本原则是什么
  • 织梦怎么做英文版网站谷歌广告代理商
  • 手机网站 分享按钮合肥seo软件
  • 网站做流量怎么赚钱的百度指数官方网站
  • 首页优化的公司seo销售话术开场白
  • 多久可以做网站seo引擎优化是做什么的
  • 什么是电商设计快速排名优化公司
  • 深圳网站设计吧深圳百度国际大厦
  • 手机网站做多少钱站长权重
  • 团购网站做不起来西安网络推广公司大全
  • 什么是网站镜像千锋教育和黑马哪个好
  • 怎么用外网校内网站做英语百度贴吧网页版入口
  • 做私服发布网站犯法吗百度识图入口
  • 如何被百度收录seo网站关键词排名优化
  • 做网站需要知道什么百度一下搜索
  • 怎样新建网站目前最牛的二级分销模式