V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
huyinjie
V2EX  ›  Python

如何获取大众点评商铺的位置信息

  •  1
     
  •   huyinjie · 2018-12-08 18:23:13 +08:00 · 3236 次点击
    这是一个创建于 1937 天前的主题,其中的信息可能已经有所发展或是发生改变。

    DianPing

    由于想要将自己平时收藏的店铺做个整理,需要解析获取到上图右侧部分的地图标签,然后从图片 url 里提取坐标的经纬度信息。但是使用 requests 解析不到网页右侧一列的部分;使用 Puppeteer 并设置 Header+Cookie 只能获取到一个 html 裸页面,结果如下图

    Puppeteer Test

    代码参考 https://gist.github.com/huyinjie/bd1733be239ed69352acd7aa33b05dfa

    8 条回复    2018-12-08 22:16:10 +08:00
    cqcn1991
        1
    cqcn1991  
       2018-12-08 18:45:08 +08:00 via Android   ❤️ 1
    关注。。。我之前只爬了地名,没拿准确经纬度。我本来是打算拿百度 API 查地址的经纬度的。。。
    zenze
        2
    zenze  
       2018-12-08 20:46:40 +08:00
    点评改版了 原来的页面是可以抓取的 现在好多字符都被替换了 地址都抓不全
    Vegetable
        3
    Vegetable  
       2018-12-08 20:55:34 +08:00   ❤️ 1
    view-source:http://www.dianping.com/shop/97297788

    搜索关键字
    shopGlat
    shopGlng
    huyinjie
        4
    huyinjie  
    OP
       2018-12-08 21:02:47 +08:00
    @Vegetable #3 太感谢了
    huyinjie
        5
    huyinjie  
    OP
       2018-12-08 21:04:56 +08:00
    @zenze #2 那个用了 CSS 的 background-position,能想办法提取到的地址,但还是需要用百度 /高德的 API 转换经纬度信息
    huyinjie
        6
    huyinjie  
    OP
       2018-12-08 21:12:31 +08:00
    @Vegetable #3 不过程序处理的时候不还是要解决 header/cookie 之类的验证问题吗,这样相当于直接用浏览器访问了
    Vegetable
        7
    Vegetable  
       2018-12-08 21:41:45 +08:00   ❤️ 1
    @huyinjie 没懂,这部分内容是 html 文本,你的代码只要修改一下最后
    await page.goto(
    'http://www.dianping.com/shop/103638985',
    { "waitUntil": "networkidle0" }
    );
    await page.waitFor(6000);
    let content = await page.content()

    let lat = /shopGlat: *"\d+?\.\d+?"/
    let lng = /shopGlng: *"\d+?\.\d+?"/
    console.log(lat.exec(content)[0])
    console.log(lng.exec(content)[0])
    await browser.close();

    就可以取到了
    shopGlat: "32.023975"
    shopGlng:"118.791344"
    huyinjie
        8
    huyinjie  
    OP
       2018-12-08 22:16:10 +08:00
    @Vegetable #7 感谢
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5887 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 02:12 · PVG 10:12 · LAX 19:12 · JFK 22:12
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.