如何解析用户在Google评论中发布的图像?

发布于 2025-02-04 08:11:36 字数 2042 浏览 2 评论 0原文

我正在研究一个刮擦项目来刮擦Google Maps评论,但是当我必须解析用户发布的图像时,我感到震惊。我尝试了这种方法,它仅给我提供了用户发布的第一张图片:

    $('.gws-localreviews__google-review').each((i,el) => {
    images[i] = $(el)
    .find(".EDblX .JrO5Xe").attr("style")
    })

我正在通过此URL刮擦Google评论:https://www.google.com/async/reviewdialog?hl = en&assamp = enc; :0x8DDDCA9EE380EF7E0,next_page_token:,sort_by:,start_index:,start_index:,ression_topic:,_ fmt:pc

这是我的响应:

[
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPgClEw3JwTLJOuf-DqC2xtZRodoavkpYVFBYqu=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOs9TSNoyYmW1GL4SH9PlkAihvWsUbMTn-8O2Sj=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipMBRGdJb3zL1rME20osajG-bosdIV8U82VTYS1n=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOBuGDXFDhJP69LNo6yI9cZWcjSVHpVfPBNoKyL=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipP7wBZt8Kilm8VF75T8amjMrZ7ZkOpmtb0nHChF=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOixJabuSd4mSHnveU5JSQ1ZszHJ6Hn-pkeosiY=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPyOXO1vnyTXVnlkPJNLlnoHYHEna36vYnrqwE=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPReBboes7S7lNklRT21pwn096JUQVJbTX3VRRA=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipNPLvARJu1vDk03r_y4fp8f7aDDvzRX-7yJklW8=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipMW3jp20hjKwuvhogH9ZC8IeH8QhQTUESH_ycNX=w100-h100-p-n-k-no)'
 ]

但是我想要一个包含一个用户映像的对象,然后是一个包含第二个用户图像的对象,然后是一个a的对象在。

我想要这样的结果:

[
{
 "All image's links posted by user 1"
},
{
 "All images links posted by user 2"
}
{
 "All images links posted by user 3"
},
{
 "All images links posted by user 4"
},
{
........
}
]

I am working on a scraping project to scrape google maps reviews, but I got struck when I have to parse images posted by users. I tried this method which only gives me the first image posted by user :

    $('.gws-localreviews__google-review').each((i,el) => {
    images[i] = $(el)
    .find(".EDblX .JrO5Xe").attr("style")
    })

I am scraping google reviews by this URL: https://www.google.com/async/reviewDialog?hl=en&async=feature_id:0x47e66e2964e34e2d:0x8ddca9ee380ef7e0,next_page_token:,sort_by:,start_index:,associated_topic:,_fmt:pc

Here is my response:

[
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPgClEw3JwTLJOuf-DqC2xtZRodoavkpYVFBYqu=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOs9TSNoyYmW1GL4SH9PlkAihvWsUbMTn-8O2Sj=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipMBRGdJb3zL1rME20osajG-bosdIV8U82VTYS1n=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOBuGDXFDhJP69LNo6yI9cZWcjSVHpVfPBNoKyL=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipP7wBZt8Kilm8VF75T8amjMrZ7ZkOpmtb0nHChF=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipOixJabuSd4mSHnveU5JSQ1ZszHJ6Hn-pkeosiY=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPyOXO1vnyTXVnlkPJNLlnoHYHEna36vYnrqwE=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipPReBboes7S7lNklRT21pwn096JUQVJbTX3VRRA=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipNPLvARJu1vDk03r_y4fp8f7aDDvzRX-7yJklW8=w100-h100-p-n-k-no)',
  'background-image:url(https://lh5.googleusercontent.com/p/AF1QipMW3jp20hjKwuvhogH9ZC8IeH8QhQTUESH_ycNX=w100-h100-p-n-k-no)'
 ]

But what I want an object containing one user images, then a second a object containing a second user images and so on.

I want the results like this:

[
{
 "All image's links posted by user 1"
},
{
 "All images links posted by user 2"
}
{
 "All images links posted by user 3"
},
{
 "All images links posted by user 4"
},
{
........
}
]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路终见情 2025-02-11 08:11:36

所以我找到了答案,这有点棘手,但是是的,它将像这样解决:

 $(".gws-localreviews__google-review").each((i, el) => {
     images[i] = $(el)
    .find(".EDblX .JrO5Xe")
    .toArray()
    .map($)
    .map(d => d.attr("style").substring(21 , d.attr("style").lastIndexOf(")")))
     });
 })

它将像这样返回响应:

[
 [
  All images posted by user 1,
 ],
 [
   All images posted by user 2,
 ],
 [.........
]

So I found the answer, it was a bit tricky but yeah it will be solved like this :

 $(".gws-localreviews__google-review").each((i, el) => {
     images[i] = $(el)
    .find(".EDblX .JrO5Xe")
    .toArray()
    .map($)
    .map(d => d.attr("style").substring(21 , d.attr("style").lastIndexOf(")")))
     });
 })

It will return the response like this:

[
 [
  All images posted by user 1,
 ],
 [
   All images posted by user 2,
 ],
 [.........
]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文