xxxx18一60岁hd中国/日韩女同互慰一区二区/西西人体扒开双腿无遮挡/日韩欧美黄色一级片 - 色护士精品影院www

  • 大小: 2KB
    文件類型: .zip
    金幣: 2
    下載: 0 次
    發(fā)布日期: 2023-12-19
  • 語(yǔ)言: Python
  • 標(biāo)簽: python??京東??

資源簡(jiǎn)介

爬取京東手機(jī)銷售與評(píng)價(jià)數(shù)據(jù),以excel表格形式存儲(chǔ),以條形圖形式展示不同品牌手機(jī)在淘寶的評(píng)價(jià)人數(shù)。可以通過(guò)更改關(guān)鍵字手機(jī)實(shí)現(xiàn)對(duì)其他商品的爬取。詳細(xì)介紹https://blog.csdn.net/weixin_42911616/article/details/81506154

資源截圖

代碼片段和文件信息

import?requests
import?pygal
import?re
from?xlwt?import?Workbook
import?matplotlib.pyplot?as?plt
import?xlrd
import?time
from?pylab?import?mpl
from?selenium?import?webdriver
from?bs4?import?BeautifulSoup


mpl.rcParams[‘font.sans-serif‘]?=?[‘FangSong‘]?#?指定默認(rèn)字體
mpl.rcParams[‘a(chǎn)xes.unicode_minus‘]?=?False?#?解決保存圖像是負(fù)號(hào)‘-‘顯示為方塊的問(wèn)題
def?key_name(?drivernumber?):
????#獲取頁(yè)面的內(nèi)容并返回
????name?=?‘手機(jī)‘
????URL_1?=?“https://search.jd.com/Search?keyword=“
????URL_2?=?“&enc=utf-8&qrst=1&rt=1&stop=1&vt=2&wq=“
????URL_3=“&cid2=653&cid3=655&page=“
????URL_4?=?“&s=1&click=0“
????URL?=?(?URL_1?+?name?+?URL_2?+?name?+?URL_3+?str(number)+URL_4)
????#driver?=?webdriver.Firefox()
????#driver.implicitly_wait(3)
????driver.get(URL)

????#?模擬下滑到底部操作
????for?i?in?range(1?5):
????????driver.execute_script(“window.scrollTo(0?document.body.scrollHeight);“)
????????time.sleep(1)

????#?將加載好的頁(yè)面源碼給bs4解析
????soup?=?BeautifulSoup(driver.page_source?“html.parser“)
????t=0

????#?進(jìn)行信息的抽取(商品名稱,價(jià)格)
????goods_info?=?soup.select(“.gl-item“)
????#driver.close()
????return?goods_info


def?manipulation_data(?goods_info?sales_count?sheet?):
????#解析獲取的HTML源碼,獲取數(shù)據(jù)并對(duì)數(shù)據(jù)進(jìn)行解析
????count=0
????for?info?in?goods_info:
????????title?=?info.select(“.p-name.p-name-type-2?a“)[0].text.strip()
????????price_str?=?info.select(“.p-price“)[0].text.strip()
????????count_str?=?info.select(“.p-commit“)[0].text.strip()
????????#print?(title)
????????price_start=price_str.find(‘¥‘)+1
????????price_end=price_str.find(‘.‘)
????????price=int(price_str[price_start:price_end])
????????#print?(price)
????????if(count_str.find(‘\n‘))>=0:
????????????count_start=count_str.find(‘\n‘)+1
????????else:
????????????count_start=0
????????if(count_str.find(‘萬(wàn)+‘))>=0:
????????????count=float(count_str[count_start:count_str.find(‘萬(wàn)‘)])*10000
????????elif(count_str.find(‘+‘))>=0:
????????????count=int(count_str[count_start:count_str.find(‘+‘)])
????????#print(count)
????????sheet.write(sales_count[‘line‘]0title)
????????sheet.write(sales_count[‘line‘]1int(price))
????????sheet.write(sales_count[‘line‘]2int(count))
????????for?key?in?sales_count.keys():
????????????if?str(title).find(‘榮耀‘)>=0:
????????????????sales_count[‘華為‘]=sales_count[‘華為‘]+(int(count))
????????????elif?str(title).find(‘Apple‘)>=0:
????????????????sales_count[‘蘋果‘]=sales_count[‘蘋果‘]+(int(count))
????????????elif?str(title).find(str(key))>=0:
????????????????sales_count[key]=sales_count[key]+(int(count))
????????sales_count[‘line‘]=?sales_count[‘line‘]?+?1
????return?sales_count

def?show(sales_count):
????#按照手機(jī)銷售量進(jìn)行排序并繪圖(網(wǎng)頁(yè)版)
????sales_count=dict(sorted(sales_count.items()key=lambda?d:d[1]reverse=True))
????print(‘正在繪制直方圖‘)
????picture=pygal.Bar()
????picture.title=“各大品牌手機(jī)評(píng)價(jià)人數(shù)直方圖??“
????picture.x_labels=sales_count.keys()
????sales_count.keys()
????picture.x_title=“手機(jī)品牌“
????picture.y_title=“評(píng)價(jià)人數(shù)“
????picture.add(‘淘寶‘sales_count.values())
????picture.ren

?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????5101??2018-08-15?13:16??jingdong.py

評(píng)論

共有 條評(píng)論