最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python爬蟲爬取淘寶商品信息(selenum+phontomjs)

 更新時(shí)間:2018年02月24日 15:21:37   作者:開心果汁  
這篇文章主要為大家詳細(xì)介紹了python爬蟲爬取淘寶商品信息,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了python爬蟲爬取淘寶商品的具體代碼,供大家參考,具體內(nèi)容如下

1、需求目標(biāo)

進(jìn)去淘寶頁(yè)面,搜索耐克關(guān)鍵詞,抓取 商品的標(biāo)題,鏈接,價(jià)格,城市,旺旺號(hào),付款人數(shù),進(jìn)去第二層,抓取商品的銷售量,款號(hào)等。

這里寫圖片描述

這里寫圖片描述

2、結(jié)果展示

這里寫圖片描述

3、源代碼

# encoding: utf-8
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
import time
import pandas as pd
time1=time.time()
from lxml import etree
from selenium import webdriver
#########自動(dòng)模擬
driver=webdriver.PhantomJS(executable_path='D:/Python27/Scripts/phantomjs.exe')
import re

#################定義列表存儲(chǔ)#############
title=[]
price=[]
city=[]
shop_name=[]
num=[]
link=[]
sale=[]
number=[]

#####輸入關(guān)鍵詞耐克(這里必須用unicode)
keyword="%E8%80%90%E5%85%8B"


for i in range(0,1):

  try:
    print "...............正在抓取第"+str(i)+"頁(yè)..........................."

    url="https://s.taobao.com/search?q=%E8%80%90%E5%85%8B&imgfile=&js=1&stats_click=search_radio_all%3A1&initiative_id=staobaoz_20170710&ie=utf8&bcoffset=4&ntoffset=4&p4ppushleft=1%2C48&s="+str(i*44)
    driver.get(url)
    time.sleep(5)
    html=driver.page_source

    selector=etree.HTML(html)
    title1=selector.xpath('//div[@class="row row-2 title"]/a')
    for each in title1:
      print each.xpath('string(.)').strip()
      title.append(each.xpath('string(.)').strip())


    price1=selector.xpath('//div[@class="price g_price g_price-highlight"]/strong/text()')
    for each in price1:
      print each
      price.append(each)


    city1=selector.xpath('//div[@class="location"]/text()')
    for each in city1:
      print each
      city.append(each)


    num1=selector.xpath('//div[@class="deal-cnt"]/text()')
    for each in num1:
      print each
      num.append(each)


    shop_name1=selector.xpath('//div[@class="shop"]/a/span[2]/text()')
    for each in shop_name1:
      print each
      shop_name.append(each)


    link1=selector.xpath('//div[@class="row row-2 title"]/a/@href')
    for each in link1:
      kk="https://" + each


      link.append("https://" + each)
      if "https" in each:
        print each

        driver.get(each)
      else:
        print "https://" + each
        driver.get("https://" + each)
      time.sleep(3)
      html2=driver.page_source
      selector2=etree.HTML(html2)

      sale1=selector2.xpath('//*[@id="J_DetailMeta"]/div[1]/div[1]/div/ul/li[1]/div/span[2]/text()')
      for each in sale1:
        print each
        sale.append(each)

      sale2=selector2.xpath('//strong[@id="J_SellCounter"]/text()')
      for each in sale2:
        print each
        sale.append(each)

      if "tmall" in kk:
        number1 = re.findall('<ul id="J_AttrUL">(.*?)</ul>', html2, re.S)
        for each in number1:
          m = re.findall('>*號(hào):&nbsp;(.*?)</li>', str(each).strip(), re.S)
          if len(m) > 0:
            for each1 in m:
              print each1
              number.append(each1)

          else:
            number.append("NULL")

      if "taobao" in kk:
        number2=re.findall('<ul class="attributes-list">(.*?)</ul>',html2,re.S)
        for each in number2:
          h=re.findall('>*號(hào):&nbsp;(.*?)</li>', str(each).strip(), re.S)
          if len(m) > 0:
            for each2 in h:
              print each2
              number.append(each2)

          else:
            number.append("NULL")

      if "click" in kk:
        number.append("NULL")

  except:
    pass


print len(title),len(city),len(price),len(num),len(shop_name),len(link),len(sale),len(number)

# #
# ######數(shù)據(jù)框
data1=pd.DataFrame({"標(biāo)題":title,"價(jià)格":price,"旺旺":shop_name,"城市":city,"付款人數(shù)":num,"鏈接":link,"銷量":sale,"款號(hào)":number})
print data1
# 寫出excel
writer = pd.ExcelWriter(r'C:\\taobao_spider2.xlsx', engine='xlsxwriter', options={'strings_to_urls': False})
data1.to_excel(writer, index=False)
writer.close()

time2 = time.time()
print u'ok,爬蟲結(jié)束!'
print u'總共耗時(shí):' + str(time2 - time1) + 's'
####關(guān)閉瀏覽器
driver.close()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • pytest自動(dòng)化測(cè)試數(shù)據(jù)驅(qū)動(dòng)yaml/excel/csv/json

    pytest自動(dòng)化測(cè)試數(shù)據(jù)驅(qū)動(dòng)yaml/excel/csv/json

    這篇文章主要為大家介紹了pytest自動(dòng)化測(cè)試數(shù)據(jù)驅(qū)動(dòng)yaml/excel/csv/json的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-06-06
  • Pytorch模型的保存/復(fù)用/遷移實(shí)現(xiàn)代碼

    Pytorch模型的保存/復(fù)用/遷移實(shí)現(xiàn)代碼

    本文整理了Pytorch框架下模型的保存、復(fù)用、推理、再訓(xùn)練和遷移等實(shí)現(xiàn),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2023-05-05
  • 解決python3.6用cx_Oracle庫(kù)連接Oracle的問(wèn)題

    解決python3.6用cx_Oracle庫(kù)連接Oracle的問(wèn)題

    這篇文章主要介紹了解決python3.6用cx_Oracle庫(kù)連接Oracle的問(wèn)題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-12-12
  • Python模塊包中__init__.py文件功能分析

    Python模塊包中__init__.py文件功能分析

    這篇文章主要介紹了Python模塊包中__init__.py文件功能,簡(jiǎn)單分析了__init__.py在調(diào)入模塊和包的過(guò)程中的作用,需要的朋友可以參考下
    2016-06-06
  • 最新評(píng)論

    陇南市| 吉林省| 罗山县| 富顺县| 收藏| 吴江市| 陆良县| 海南省| 远安县| 名山县| 吴忠市| 化德县| 浙江省| 保德县| 敦煌市| 克什克腾旗| 秭归县| 霍州市| 时尚| 辉县市| 西藏| 汽车| 平舆县| 六枝特区| 法库县| 五常市| 龙海市| 鄂尔多斯市| 嘉定区| 安康市| 西华县| 新郑市| 鄂尔多斯市| 安溪县| 夏河县| 阜城县| 巴林左旗| 抚州市| 泽库县| 潞城市| 仁寿县|