python模拟登录饿了么并爬取指定位置附近的商家信息

 此篇内容使用到了以下模块:

1.使用openpyxl实现excel的读写

2.使用pypinyin实现汉子转拼音

3.使用geohash获取经纬度编码

4.使用requests中的utils方法实现cookies转字典和字典转cookies

5.使用json对列表和字典以及字符串之间进行转换

通过此次的学习可以爬取到全国2000多个城市指定位置附近的商家信息,如果再进一步挖掘的就具备了很大的商业价值

import requests
from pypinyin import lazy_pinyin
import geohash
import json
import openpyxl
session = requests.session()


# 将处理后的信息写入excel文件中
def write_info():
    rest_list = get_nearby_restaurants_by_menu()
    if rest_list != False:
        # 新建excel
        wb = openpyxl.Workbook()
        # 获取工作表
        sheet = wb.active
        # 工作表名称
        sheet.title = "饿了么商家信息"
        # 设置单元格的列宽
        sheet.column_dimensions['A'].width = 40
        sheet.column_dimensions['B'].width = 20
        sheet.column_dimensions['C'].width = 60
        sheet.column_dimensions['D'].width = 20
        she

猜你喜欢

转载自blog.csdn.net/LSW_JAVADP/article/details/103097779
今日推荐