python-3.x - 爱彼迎房东在特定城市或地点的排名

标签 python-3.x web-scraping

我想通过从包含该地区个人评论和排名的页面中抓取数据来获取 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/

相关文章:

python-3.x - 如何将 float 追加到列表中?

python - Scrapy 和图像抓取的问题

python - 在 Matplotlib FuncAnimation 中制作动画时使用附加函数的困难

python-3.x - 如何使用 beautifulsoup 查找没有特定属性的标签?

python-3.x - 一步步: Installing Python 3. 3、Ubuntu 12.04上的Lighttpd & Pymongo

python - 如何在我的Mapper和Reducer中使用此代码?我想在Google集群中运行此代码

excel - Vba - 使用 ng-click 进行网页抓取

python - Beautifulsoup4中,获取某个元素的所有子元素,但不获取该子元素的子元素

python - 如何从javascript中提取json格式的数据?

python - 从雅虎财经抓取数据