爬取豆瓣音樂Top250並存入xls
import requests from bs4 import BeautifulSoup import re import xlwt class DoubanMusic: def __init__(self,pageIndex): self.pageIndex = 0 self.user_agent = 'Mozila/5.0' self.headers = {'User-agent':self.user_agent} self.music_list = [] def getHtml(self): try: url = 'https://music.douban.com/top250?'+ str(self.pageIndex) r = requests.get(url, self.headers) r.encoding = 'utf-8' r.raise_for_status() return r.text except: return '' def parseHtml(self): soup = BeautifulSoup(self.getHtml(), 'html.parser') for music in soup.findAll('tr',{'class':'item'}): musicUrl = music.a['href'] name = music.a.get_text().strip() detail = music.find('p',{'class':'pl'}).get_text().strip('/') singer = detail[0].strip() date = detail[1].strip() source = detail[2].strip() home= detail[3].strip() singeType = detail[4].strip() score = music.find('span',{'class':'rating_nums'}).get_text().strip('(').strip(')').strip() words = music.find('span',{'class':'pl'}).get_text().strip() self.music_list.append([name,score,words,musicUrl]) def load(self,datalist): file = xlwt.Workbook() sheet = file.add_sheet('豆瓣音樂Top2500', cell_overwrite_ok=True) col = (u'歌名',u'歌手',u'得分',u'啥麼') for i in range(0,3): sheet.write(0,i,col[i]) for i in range(0,250): data = datalist[i] for j in range(0,3): sheet.write(i+1,j,data[j]) file.save('豆瓣音樂Top2500.xls') def start(self): print('開始為您抓取豆瓣音樂Top250') while(self.pageIndex<=225): print('正在抓取第%d頁'%(self.pageIndex/25+1)) self.getHtml() self.pageIndex+=25 print("抓取完成") self.load(self.music_list) music = DoubanMusic(0) music.start()
相關推薦
爬取豆瓣音樂Top250並存入xls
import requests from bs4 import BeautifulSoup import re import xlwt class DoubanMusic: def __ini
Python3 爬取豆瓣圖書Top250並存入Excel中
#coding=utf-8 import re import xlwt import requests from bs4 import BeautifulSoup def getHtml(url): headers = {'User-Agent': 'Mo
爬蟲學習之11:爬取豆瓣電影TOP250並存入資料庫
本次實驗主要測試使用PyMySQL庫寫資料進MySQL,爬取資料使用XPATH和正則表示式,在很多場合可以用XPATH提取資料,但有些資料項在網頁中沒有明顯特徵,用正則表示式反而反而更輕鬆獲取資料。直接上程式碼:from lxml import etree impo
Python爬蟲實戰(3)-爬取豆瓣音樂Top250資料(超詳細)
前言 首先我們先來回憶一下上兩篇爬蟲實戰文章: 第一篇:講到了requests和bs4和一些網頁基本操作。 第二篇:用到了正則表示式-re模組 今天我們用lxml庫和xpath語法來爬蟲實戰。 1.安裝lxml庫 window:直接用pip去
利用python爬取豆瓣音樂TOP250
最近無所事事,在逼乎看到別人爬取了豆瓣電影,發現挺適合我這菜雞練練手 所以我來爬音樂。。 #對不起豆瓣,又是爬你。。 目標網站:https://music.douban.com/top250?start=0 首先正常瀏覽分析網頁 開啟網址,點選下一頁,發現網站URL變成
python爬蟲——爬取豆瓣電影top250資訊並載入到MongoDB資料庫中
最近在學習關於爬蟲方面的知識,因為剛開始接觸,還是萌新,所以有什麼錯誤的地方,歡迎大家指出 from multiprocessing import Pool from urllib.request import Request, urlopen import re, pymongo index
爬蟲專案:requests爬取豆瓣電影TOP250存入excel中
這次爬取是爬取250部電影的相關內容,分別用了requests請求url,正則表示式re與BeautifulSoup作為內容過濾openpyxl作為excel的操作模組,本人為才學不久的新手,程式碼編寫有點無腦和囉嗦,希望有大神能多提建議 首先,程式碼清單如下:
scrapy爬取豆瓣電影top250
imp port 爬取 all lba item text request top 1 # -*- coding: utf-8 -*- 2 # scrapy爬取豆瓣電影top250 3 4 import scrapy 5 from douban.items i
團隊-爬取豆瓣電影TOP250-需求分析
影評 鏈接 lock 分析 strong str 需求分析 豆瓣 信息 團隊-爬取豆瓣電影TOP250-需求分析 需求:爬取豆瓣電影TOP250 *向用戶展示電影的排名,分數,名字,簡介,導演,演員,前10條影評信息,鏈接信息 實現思路: 分析豆瓣電影TOP250
《團隊-爬取豆瓣電影TOP250-需求分析》
round ack 地址 align wid ica san pad ext 需求: 1.搜集相關電影網址 2.實現相關邏輯的代碼 項目步驟: 1.通過豆瓣網搜索關鍵字,獲取相關地址 2.根據第三方包實現相關邏輯《團隊-爬取豆瓣電影TOP250-需求分析》
團隊-爬取豆瓣電影TOP250-開發環境搭建過程
技術 團隊 img mage www. 9.png 官網下載 har image 從官網下載安裝包(http://www.python.org)。 安裝Python 選擇安裝路徑(我選的默認) 安裝Pycharm 1.從官網下載安裝包(ht
《團隊-爬取豆瓣電影TOP250-設計文檔》
python top 賬號 集成開發環境 python3 搭建環境 電影 settings 解耦 搭建環境: 1.安裝python3.4 2.安裝pycharm集成開發環境 3.安裝Git for Windows 4.安裝python第三方包 bs4開發階段: 1
團隊-爬取豆瓣電影top250-模塊開發過程
rds tps tde 轉換 /usr sub bigger pen 其他 項目托管平臺地址:https://gitee.com/nothingbigger/DouBantop250 開發模塊功能: 完善爬取功能、補全獲取數據的漏洞,開發時間:1天 #!/usr
團隊-爬取豆瓣電影TOP250-簡單團隊一階段互評
思維 lec sel 敏捷 努力 查找 pan sele 參與 團隊名稱:簡單 學號:2015035107009 得分:10 原因:配合默契,負責女生部分 學號:2015035107224 得分:9 原因:思維敏捷,領導了大體思路 學號:2015035107005 得分:6
簡單團隊-爬取豆瓣電影top250-設計文檔
分享圖片 top 文檔 功能需求 class cnblogs 項目介紹 面向 設計文檔 項目介紹: 功能需求: 面向用戶: 未來規劃: 以上內容源自於在課上做的ppt內容,絕對本組ppt,並且真實有效。 簡單團隊-爬取豆瓣電影top
Scrapy爬取豆瓣電影top250的電影數據、海報,MySQL存儲
p地址 rom gin ani char 代碼 pipeline print 關閉數據庫 從GitHub得到完整項目(https://github.com/daleyzou/douban.git)1、成果展示數據庫本地海報圖片2、環境(1)已安裝Scrapy的Pycharm
Python爬蟲:現學現用Xpath爬取豆瓣音樂
9.1 tree when href scrapy 發現 pat 直接 where 爬蟲的抓取方式有好幾種,正則表達式,Lxml(xpath)與Beautiful,我在網上查了一下資料,了解到三者之間的使用難度與性能 三種爬蟲方式的對比。 抓取方式 性能 使用難度
爬蟲-爬取豆瓣圖書TOP250
info spa data inf code pla select lac lec import requests from bs4 import BeautifulSoup def get_book(url): wb_data = requests.get(u
Python 爬取qqmusic音樂url並批量下載
QQ col expr IE filename 代碼 都是 sles () qqmusic上的音樂還是不少的,有些時候想要下載好聽的音樂,但有每次在網頁下載都是煩人的登錄什麽的。於是,來了個qqmusic的爬蟲。 至少我覺得for循環爬蟲,最核心的應該就是找到待爬元
用Requests和正則表示式爬取豆瓣圖書TOP250
思路和上文大同小異。 import requests from requests.exceptions import RequestException import re import json headers = {'User-Agent':'Mozilla/5.0(Macinto