日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

使用python抓取美团商家信息

發布時間:2023/12/20 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 使用python抓取美团商家信息 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

抓取美團商家信息

import requests from bs4 import BeautifulSoup import jsonurl = 'http://bj.meituan.com/' url_shop = 'http://bj.meituan.com/shop/{}' headers = {'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8','Accept-Encoding':'gzip, deflate, sdch','Accept-Language':'zh-CN,zh;q=0.8','Cache-Control':'max-age=0','DNT':'1','Host':'bj.meituan.com','Proxy-Connection':'keep-alive','Referer':'http://bj.meituan.com/shop/286725?acm=UwunyailsW15518532529028663069.286725.1&mtt=1.index%2Fdefault%2Fpoi.pz.1.j4cijrmg&cks=58899','Upgrade-Insecure-Requests':'1','User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36' }# 得到所有的二級菜單url def get_start_menu_links():html = requests.get(url).textsoup = BeautifulSoup(html, 'lxml')links = [link.find('div').find('div').find('dl').find('dt').find('a')['href'] for link in soup.find_all('div',class_='J-nav-item') ]return linksdef get_shop_ids(url, headers=None):html = requests.get(url, headers=headers).textsoup = BeautifulSoup(html, 'lxml')content_id = json.loads(soup.find('div', class_='J-scrollloader cf J-hub')['data-async-params'])return json.loads(content_id.get('data')).get('poiidList')def main():start_menu_links = get_start_menu_links()for link in start_menu_links:for pageNum in range(4,5):category_url = link + '/all/page{}'.format(pageNum)for shop_id in get_shop_ids(category_url, headers=headers):html = requests.get(url_shop.format(shop_id), headers=headers).textsoup = BeautifulSoup(html, 'lxml')shop_detail = soup.find('div', class_='summary biz-box fs-section cf')print("==================================pageNum %d shop_id: %d===================================================" % (pageNum,shop_id ))try:shop_detail.find('div', class_='fs-section__left').find('h2').find('span').textexcept:continueprint("名稱: " + shop_detail.find('div', class_='fs-section__left').find('h2').find('span').text)print("地址: " + shop_detail.find('div', class_='fs-section__left').find('p', class_='under-title').find('span').text)print("聯系方式: " + shop_detail.find('div', class_='fs-section__left').find('p', class_='under-title').find_next_sibling().text)if '__main__' == __name__:main()

總結

以上是生活随笔為你收集整理的使用python抓取美团商家信息的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。