i am parsing site yelp.com , i am getting name of dishes name_of_dishs=yelp_beat.findAll('div',{'class':'lemon--div__373c0__1mboc businessName__373c0__1fTgn border-color--default__373c0__2oFDT'})
(Soco, SalaThai,Bunker) and also i need to get reviews of dishes but when i am using nested loop it's not working
import requests
from bs4 import BeautifulSoup
base_url = "https://www.yelp.com/search?find_desc=Restaurants&find_loc=New%20York%2CNY&start=30"
yelp = requests.get(base_url)
yelp_beat = BeautifulSoup(yelp.text, 'html.parser')
name_of_dishs=yelp_beat.findAll('div',{'class':'lemon--div__373c0__1mboc businessName__373c0__1fTgn border-color--default__373c0__2oFDT'})
for dish in name_of_dishs:
#print(dish.text)
for reviews in dish.findAll('span',{'lemon--span__373c0__3997G text__373c0__2pB8f reviewCount__373c0__2r4xT text-color--mid__373c0__3G312 text-align--left__373c0__2pnx_'}):
print(reviews.text)
it missing the class
for argument and I have simplified the selector and select the li
instead
yelp_beat = BeautifulSoup(yelp.text, 'html.parser')
theList = yelp_beat.select('.mainContentContainer__373c0__32Mqa .domtags--li__373c0__3TKyB.list-item__373c0__M7vhU')
for li in theList:
name_of_dishs = li.select_one('h3 a')
reviews = li.select_one('.reviewCount__373c0__2r4xT')
if not name_of_dishs or not reviews:
continue
print('{}: {}'.format(name_of_dishs.text, reviews.text))
result
Jajaja: 576 reviews
Balzem: 364 reviews
Jane: 2995 reviews
PMF Pardon My French: 830 review