Невозможно выполнить команду "Показать больше отзывов" в моем веб-браузере - PullRequest
1 голос
/ 13 июля 2020

Я пробовал использовать Selenium, но не смог нажать кнопку «Показать больше отзывов». Я пытаюсь очистить все отзывы на веб-странице. У меня также возникают проблемы с получением звездного рейтинга во всех обзорах. Я был бы очень признателен за помощь. https://appgrooves.com/app/kotak-811-and-mobile-banking-by-kotak-mahindra-bank-ltd/positive

import requests
from bs4 import BeautifulSoup
import pandas as pd

Final = []
URL = "https://appgrooves.com/app/kotak-811-and-mobile-banking-by-kotak-mahindra-bank-ltd/positive"

r = requests.get(URL)
soup = BeautifulSoup(r.content, 'html.parser')
reviews = []  # a list to store reviews

review_divs = soup.select('div.tab-content')
for element in review_divs :
    review = {'Review_Title': 'appgrooves reviews', 'URL': ' ',
              'Review': element.find('div', {'class': ['body-content', 'collapse']}).text,
              'Stars' : len(element.find('div', "rate-date-container").findAll("i", "fas fa-star"))}
    reviews.append(review)

Final.extend(reviews)

df = pd.DataFrame(Final)
print(df)

1 Ответ

1 голос
/ 13 июля 2020
import requests
import pandas as pd
from bs4 import BeautifulSoup


url = "https://appgrooves.com/app/kotak-811-and-mobile-banking-by-kotak-mahindra-bank-ltd/positive"
soup = BeautifulSoup(requests.get(url).content, 'lxml')

all_data = []
while True:
    for r in soup.select('[id^="positive_mosthelpful_reviews"]'):
        rating = r.select_one('.rating-stars')['class'][-1].split('-')[-1]
        txt = r.select_one('[id^="review-item-body"]').get_text(strip=True)

        all_data.append({'Review_Title': 'appgrooves reviews', 'URL': ' ',
                         'Review': txt, 'Stars': rating})

        print(rating)
        print(txt)
        print('-' * 80)

    btn = soup.select_one('button:contains("Show More Positive Reviews")')
    if not btn:
        break

    data = requests.get('https://appgrooves.com' + btn['data-url-ajax'], headers = {'X-Requested-With': 'XMLHttpRequest'}).json()
    soup = BeautifulSoup(data['data']['preview_html'], 'lxml')

df = pd.DataFrame(all_data)
print(df)
df.to_csv('data.csv')

Печатает:

          Review_Title URL                                             Review Stars
0   appgrooves reviews      Kotak bank has nice app, I hold several intern...     5
1   appgrooves reviews      Kotak bank has nice app, I hold several intern...     5
2   appgrooves reviews      I love using this app for its easiness except ...     4
3   appgrooves reviews      New update and Face ID login made the app go f...     4
4   appgrooves reviews      This is the best mobile banking apps that I ha...     5
5   appgrooves reviews      I have used many Indian as well as global bank...     5
6   appgrooves reviews      Update: I have un-installed the app and reinst...     5
7   appgrooves reviews      Love the Kotak app totally, simple to use inte...     5
8   appgrooves reviews      Very user friendly and at the same time loaded...     5
9   appgrooves reviews      2 days back I received mandatory update and af...     5
10  appgrooves reviews      Best user friendly banking mobile app. Intuiti...     5
11  appgrooves reviews      App not working after latest update which has ...     5
12  appgrooves reviews      Connecting credit card payment / net banking /...     5
13  appgrooves reviews      Takes few seconds to make credit card payment....     5
14  appgrooves reviews      I I really trust this app - it has multiple la...     5
15  appgrooves reviews      This so far has turned out to be the fastest a...     5
16  appgrooves reviews      I updated to the latest version of Kotak app, ...     3
17  appgrooves reviews      The app is too good and was working fine until...     4

и сохраняет data.csv.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...