我想通过从包含该地区个人评论和排名的页面中抓取数据来获取 Airbnb 网站上房东的排名。我可以从页面获取评论数量,但不知道排名。以下是我的代码
from bs4 import BeautifulSoup # BeautifulSoup is in bs4 package
import requests
URL = input("Please enter an URL to the number of reviews \n")
#'https://www.airbnb.co.in/users/show/154131896'
content = requests.get(URL)
soup = BeautifulSoup(content.text, 'html.parser')
row = soup.find('div')
#Extract and return first occurrence
print("=========Text Result==========")
print(row.get_text())
#Print row as text
divs = soup.find_all('div', { "class" : "_5kaapu"})
#Find all the records for reviews
for i in divs:
childr = i.findChildren("span" , recursive=False)
for child in childr:
iwant = child.text
print(iwant)
contentTable = soup.find('div', { "class" : "_5kaapu"})
# Use dictionary to pass key : value pair
rows = contentTable.find_all('span',{"class": "_1ax9t0a"})
for row in rows:
print(" The host have ", row.get_text())
最佳答案
这样做的一种方法是:
from bs4 import BeautifulSoup
import requests
content = requests.get('https://www.airbnb.co.in/users/show/154131896')
soup = BeautifulSoup(content.text, 'html.parser').find_all('span', {"class": "_krjbj"})
for item in soup[:2]:
print(item.text)
打印出:
Rating 4.97 out of 5;
36 reviews
关于python-3.x - 爱彼迎房东在特定城市或地点的排名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63705608/