Der Versuch, BeautifulSoup zu verwenden, um Yelp -Bewertungen zu kratzen und nach CSV zu exportieren, hat der CSV jedochPython

Python-Programme
Guest
 Der Versuch, BeautifulSoup zu verwenden, um Yelp -Bewertungen zu kratzen und nach CSV zu exportieren, hat der CSV jedoch

Post by Guest »

Ich versuche, 100 Bewertungen/Bewertungen in einem Yelp -Restaurant für eine Aufgabe mit BeautifulSoup zu kratzen. Ich suche speziell nach:
Bewertungskommentar
Bewertungs -ID
Bewertungsbewertung < /p>
Ich bin ziemlich neu in Python und ich habe das Gefühl, ich habe das Gefühl etwas äußerst offensichtliches < /p>
Hier ist was ich bisher habe: < /p>

Code: Select all

from bs4 import BeautifulSoup
import urllib.request
< /code>
url = 'https://www.yelp.com/biz/ichiran-times-square-new-york-4?osq=Ichiban+Ramen' ourUrl = urllib.request.urlopen(url)

Code: Select all

soup = BeautifulSoup(ourUrl,'html.parser') type(soup) print(soup.prettify())

Code: Select all

for i in soup.find_all('div', {'class':" arrange-unit__373c0__3XPkE arrange-unit-fill__373c0__38Zde border-color--default__373c0__r305k"}): ID.append(i.find("div").get("aria-label"))

Code: Select all

soup.find('p', {'class':"comment__373c0__Nsutg css-n6i4z7"})

Code: Select all

i = soup.find('p', {'class':"comment__373c0__Nsutg css-n6i4z7"}) i.text

Code: Select all

review=[]
rating = []
ID = []

for x in range(0,10):

url = "https://www.yelp.com/biz/ichiran-times-square-new-york-4?osq=Ichiban+Ramen="+str(10*x)

ourUrl = urllib.request.urlopen(url)

soup = BeautifulSoup(ourUrl,'html.parser')

#for i in soup,

for i in soup.find_all('div', {'class':" i-stars__373c0___sZu0 i-stars--regular-5__373c0__20dKs border-color--default__373c0__1yxBb overflow--hidden__373c0__1TJqF"}):
per_rating = i.text
rating.append(per_rating)

for i in soup.find_all('span', {'class':" arrange-unit__373c0__3XPkE arrange-unit-fill__373c0__38Zde border-color--default__373c0__r305k"}):
ID.append(i.find("div").get("aria-label"))

for i in soup.find_all('p', {'class':"comment__373c0__Nsutg css-n6i4z7"}):
per_review=i.text
review.append(per_review)
< /code>
len(review)

Hier ist mein Versuch, nach CSV zu exportieren, wo ich nur Bewertungstext erhalte und sonst nichts:

Code: Select all

with open('Review.csv','a',encoding = 'utf-8') as f:
for each in review:
f.write(each+'\n')

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post