Python爬取附近餐館信息代碼示例
本代碼主要實(shí)現(xiàn)抓取大眾點(diǎn)評(píng)網(wǎng)中關(guān)村附近的餐館有哪些,具體如下:
import urllib.request
import re
def fetchFood(url):
# 模擬使用瀏覽器瀏覽大眾點(diǎn)評(píng)的方式瀏覽大眾點(diǎn)評(píng)
headers = {'User-Agent',
'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36'}
opener = urllib.request.build_opener()
opener.addheaders = [headers]
data = opener.open(url).read()
data = data.decode('utf')
print('================================抓取的頁(yè)面數(shù)據(jù)=======================================')
print(data) # 打印抓取的頁(yè)面
print('================================獲取的餐館信息====================================')
foodNameSet = set(re.compile(r'<img title="(.*?)"', re.DOTALL).findall(data))
number = 0
for i in foodNameSet:
number = number + 1
print("第%d個(gè)餐館: %s" % (number, i))
foodUrl = "http://www.dianping.com/search/category/2/10/r1488"
fetchFood(foodUrl)
輸出結(jié)果:
"D:\ProgramFiles\python\python.exe"D:/zhangzh/program/MyGitHub/python3-webapp-demo/www/dzdp.py
================================抓取的頁(yè)面數(shù)據(jù)=======================================
<!DOCTYPEhtml>
<html>
<head>
<metacharset="UTF-8"/>
<metahttp-equiv="X-UA-Compatible"content="IE=edge"/>
<script>(function(n){vare;e="http://catdot.dianping.com/broker-service/api/js",n.onerror=function(n,o,r){vari=encodeURIComponent,t=+newDate();(newImage).src=e+"?error="+i(n)+"&file="+i(o)+"&line="+i(r)+"×tamp="+t}})(window);</script>
<title>北京中關(guān)村美食-大眾點(diǎn)評(píng)網(wǎng)</title>
......此處省略
<liclass="">
<divclass="pic">
<atarget="_blank"href="/shop/33562041" rel="external nofollow" rel="external nofollow" rel="external nofollow" title="">
<imgtitle="渝是乎(中關(guān)村店)"alt="渝是乎(中關(guān)村店)"data-src="http://p0.meituan.net/ugcpic/023ff4be1a239be5b7f13ac328bc6c5d%40249w_249h_0e_1l%7Cwatermark%3D1%26%26r%3D1%26p%3D9%26x%3D2%26y%3D2%26relative%3D1%26o%3D20"/>
</a>
</div>
<divclass="txt">
<divclass="tit">
<aonclick="document.hippo.ext({cl_i:10,query_id:'4ab097b5-d3b6-441b-a684-8b58c0704567'}).mv('cl_to_s',33562041);
"data-hippo-type="shop"title="渝是乎(中關(guān)村店)"target="_blank"href="/shop/33562041" rel="external nofollow" rel="external nofollow" rel="external nofollow" >
<h4>渝是乎(中關(guān)村店)</h4>
</a>
<divclass="promo-icon">
<atarget="_blank"href="/shop/33562041#waimai" rel="external nofollow"
class="iout"title="本店支持在線下單,足不出戶,外送到家!"></a>
</div>
<atarget="_blank"href="/search/branch/2/0_33562041/g0" rel="external nofollow"
module="list-branch"
class="shop-branch">分店</a>
</div>
<divclass="comment">
<spanclass="sml-rank-starssml-str50"title="五星商戶"></span>
<ahref="/shop/33562041#comment" rel="external nofollow" class="review-num"target="_blank"module="list-readreview"
>
<b>1536</b>
條點(diǎn)評(píng)</a>
<emclass="sep">|</em>
<ahref="/shop/33562041" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="mean-price"target="_blank">
人均
<b>¥42</b>
</span>
</a>
</div>
<divclass="tag-addr">
<ahref="/search/category/2/10/g102" rel="external nofollow" ><spanclass="tag">川菜</span></a>
<emclass="sep">|</em>
<ahref="/search/category/2/0/r1488" rel="external nofollow" ><spanclass="tag">中關(guān)村</span></a>
<spanclass="addr">榆樹林1號(hào)</span>
</div>
<spanclass="comment-list">
<span>口味<b>9.1</b></span>
<span>環(huán)境<b>8.7</b></span>
<span>服務(wù)<b>8.3</b></span>
</span>
</div>
<divclass="svr-info">
......此處省略
</script>
</body></html>
================================獲取的餐館信息====================================
第1個(gè)餐館:重八牛府(之初入江湖店)
第2個(gè)餐館:紐約客美式餐廳(新中關(guān)店)
第3個(gè)餐館:Chatuchak加都加曼谷潮流甜品
第4個(gè)餐館:新凈雅烹小鮮
第5個(gè)餐館:那家小館(中關(guān)村店)
第6個(gè)餐館:谷得一
第7個(gè)餐館:唐廊.樸禪(當(dāng)代商城店)
第8個(gè)餐館:小福樓餐廳
第9個(gè)餐館:食寶街
第10個(gè)餐館:渝是乎(中關(guān)村店)
第11個(gè)餐館:品咖啡
第12個(gè)餐館:小吊梨湯(融科店)
第13個(gè)餐館:魚八斗老麻水煮魚(酸菜魚)
第14個(gè)餐館:鰻鰻的愛(ài)(新中關(guān)購(gòu)物中心店)
第15個(gè)餐館:速度牛排
Processfinishedwithexitcode0
總結(jié)
以上就是本文關(guān)于Python爬取附近餐館信息代碼示例的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:
Python爬取當(dāng)當(dāng)、京東、亞馬遜圖書信息代碼實(shí)例
matplotlib在python上繪制3D散點(diǎn)圖實(shí)例詳解
如有不足之處,歡迎留言指出。感謝朋友們對(duì)本站的支持!
- python爬蟲_微信公眾號(hào)推送信息爬取的實(shí)例
- python爬蟲爬取淘寶商品信息
- python登錄并爬取淘寶信息代碼示例
- Python爬取當(dāng)當(dāng)、京東、亞馬遜圖書信息代碼實(shí)例
- python爬蟲爬取淘寶商品信息(selenum+phontomjs)
- 使用python爬蟲實(shí)現(xiàn)網(wǎng)絡(luò)股票信息爬取的demo
- python3爬取各類天氣信息
- 一個(gè)簡(jiǎn)單的python爬蟲程序 爬取豆瓣熱度Top100以內(nèi)的電影信息
- Python探索之爬取電商售賣信息代碼示例
- python爬取亞馬遜書籍信息代碼分享
- python3爬取淘寶信息代碼分析
- python爬取哈爾濱天氣信息
相關(guān)文章
python selenium爬取斗魚所有直播房間信息過(guò)程詳解
這篇文章主要介紹了python selenium爬取斗魚所有直播房間信息過(guò)程詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-08-08
django使用sqlite3統(tǒng)計(jì)前臺(tái)站點(diǎn)訪問(wèn)數(shù)量示例
這篇文章主要為大家介紹了django使用sqlite3統(tǒng)計(jì)前臺(tái)站點(diǎn)訪問(wèn)數(shù)量示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-08-08
Python基礎(chǔ)篇之初識(shí)Python必看攻略
下面小編就為大家?guī)?lái)一篇Python基礎(chǔ)篇之初識(shí)Python必看攻略。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2016-06-06
python2 與 python3 實(shí)現(xiàn)共存的方法
這篇文章主要介紹了python2 與 python3 實(shí)現(xiàn)共存的方法,本文圖文并茂給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2018-07-07
matplotlib繪制正余弦曲線圖的實(shí)現(xiàn)
這篇文章主要介紹了matplotlib繪制正余弦曲線圖的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02
解決pip安裝tensorflow中出現(xiàn)的no module named tensorflow.python 問(wèn)題方法
這篇文章主要介紹了解決pip安裝tensorflow中出現(xiàn)的no module named tensorflow.python 問(wèn)題方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-02-02

