Answer the question
In order to leave comments, you need to log in
Why is BeautifulSoup's find not finding the tag?
I can't figure out why it can't find review tags. everything works for other tags.
import requests
from bs4 import BeautifulSoup
from fake_useragent import UserAgent
ua = UserAgent()
response = requests.get(
url='https://play.google.com/store/apps/details?id=ru.mail.mailapp&hl=ru&gl=US&showAllReviews=true',
headers={'user-agent': f'{ua.random}'}).text
soup = BeautifulSoup(response, 'lxml')
feedback = soup.find('span', jsname='bN97Pc').text
print(feedback)
Answer the question
In order to leave comments, you need to log in
Everything is as simple as in quantum physics. With our script, we save the request response to disk. Next, open the file in notepad and see if there is a given tag with the desired class. In 99.9% - no. In this case, let's go to google to smoke selenium mana. Or you can do without selenium. There are many ways, the main thing is to have enough imagination.
Here is one of the options (it may not work for you, or it may work, and tomorrow it will break - I don’t know.)
import requests
from bs4 import BeautifulSoup
import json
response = requests.get(
url='https://play.google.com/store/apps/details?id=ru.mail.mailapp&hl=ru&gl=US&showAllReviews=true',
headers={'user-agent':'Hacked by HottabXP!'})
soup = BeautifulSoup(response.text,"lxml")
dirty_comments = soup.find_all('script')[34].string # Методом тыка определяем, что json с коментами хранится
# в 35 теге <script> и преобразовываем данные внутри тега в строку
valid_json = dirty_comments[dirty_comments.find(' data:')+6:dirty_comments.find(', sideChannel')] # Вырезаем всё, что
# находится между data: (плюс 6 символов) и sideChannel
comments_json = json.loads(valid_json) # Тут уже работаем с обычным json
for comment in comments_json[0]:
user_comment = comment[4] # Комментарий пользователя
try:
author_answer = comment[7][1] # Ответ на комментарий пользователя (может быть None)
except:
author_answer = '' # Если None, тогда в author_answer помещаем пустую строку
print(user_comment)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question