91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

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

資源簡介

爬取京東手機銷售與評價數據,以excel表格形式存儲,以條形圖形式展示不同品牌手機在淘寶的評價人數。可以通過更改關鍵字手機實現對其他商品的爬取。詳細介紹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‘]?#?指定默認字體
mpl.rcParams[‘axes.unicode_minus‘]?=?False?#?解決保存圖像是負號‘-‘顯示為方塊的問題
def?key_name(?drivernumber?):
????#獲取頁面的內容并返回
????name?=?‘手機‘
????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)

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

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


def?manipulation_data(?goods_info?sales_count?sheet?):
????#解析獲取的HTML源碼,獲取數據并對數據進行解析
????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(‘萬+‘))>=0:
????????????count=float(count_str[count_start:count_str.find(‘萬‘)])*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):
????#按照手機銷售量進行排序并繪圖(網頁版)
????sales_count=dict(sorted(sales_count.items()key=lambda?d:d[1]reverse=True))
????print(‘正在繪制直方圖‘)
????picture=pygal.Bar()
????picture.title=“各大品牌手機評價人數直方圖??“
????picture.x_labels=sales_count.keys()
????sales_count.keys()
????picture.x_title=“手機品牌“
????picture.y_title=“評價人數“
????picture.add(‘淘寶‘sales_count.values())
????picture.ren

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

評論

共有 條評論