前言
本文的文字及圖片來源于網路,僅供學習、交流使用,不具有任何商業用途,如有問題請及時聯系我們以作處理,
很多人學習python,不知道從何學起,
很多人學習python,掌握了基本語法過后,不知道在哪里尋找案例上手,
很多已經做案例的人,卻不知道如何去學習更加高深的知識,
那么針對這三類人,我給大家提供一個好的學習平臺,免費領取視頻教程,電子書籍,以及課程的源代碼!
QQ群:961562169
今年的國慶節還有半個月就要來了,相信很多的小伙伴還是非常期待這個小長假的,國慶節是一年中的小長假,很多的朋友會選擇旅行來度過,中國的旅游城市有很多,旅游景點也是數不勝數,


那么,2020國內十一國慶適合去哪里游玩呢?
專案目標
爬取美團旅游景點評論
受害者網址
[https://chs.meituan.com/](https://chs.meituan.com/)

代碼
安裝庫
pip install requests
pip install time
匯入工具
import requests
import time
決議網站,爬取資料
for page in range(10, 101, 10):
time.sleep(1)
url = 'https://www.meituan.com/ptapi/poi/getcomment?id=1161635&offset=0&pageSize={}&sortType=1'.format(page)
headers = {
'Host': 'www.meituan.com',
'Pragma': 'no - cache',
'Referer': 'https: // www.meituan.com / zhoubianyou / 1161635 /',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36'
}
response = requests.get(url=url, headers=headers)
html_data = https://www.cnblogs.com/41280a/p/response.json()
info_data = html_data['comments']
for i in info_data:
info = i['comment']
保存資料
for i in info_data:
info = i['comment']
with open('美團評論.csv', mode='a', encoding='utf-8-sig', newline='') as f:
f.write(info)
print(info)
運行代碼,效果如下圖


轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/76726.html
標籤:Python
