Python爬虫实战练习:爬取美团旅游景点评论数据

内容摘要
本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。很多人学习python,不知道从何学起
文章正文

本文的文字及图片来源于网络,仅供学习、交流使用,不具有任何商业用途,如有问题请及时联系我们以作处理。

今年的国庆节还有半个月就要来了,相信很多的小伙伴还是非常期待这个小长假的。国庆节是一年中的小长假,很多的朋友会选择旅行来度过。中国的旅游城市有很多,旅游景点也是数不胜数。

那么,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 = 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)

代码注释
[!--zhushi--]

作者:喵哥笔记

IDC笔记

学的不仅是技术,更是梦想!