Python 3.x Python-如何在beautifulsoup(TripAdvisor)中获取内部类文本

Python 3.x Python-如何在beautifulsoup(TripAdvisor)中获取内部类文本,python-3.x,beautifulsoup,Python 3.x,Beautifulsoup,我试图从python web scrape程序中获取TripAdvisor中特定日期范围内特定区域内所有酒店的价格。我的程序使用selenium select日期范围加载站点,并在解析数据到BeautifulSoup时加载。 价格数据位于站点的内部类中。 我正在使用这段代码,并给我ResultSet对象没有属性错误 html = browser.page_source textobj = BeautifulSoup(html,"html.parser") text1=tex

我试图从python web scrape程序中获取TripAdvisor中特定日期范围内特定区域内所有酒店的价格。我的程序使用selenium select日期范围加载站点,并在解析数据到BeautifulSoup时加载。 价格数据位于站点的内部类中。

我正在使用这段代码,并给我ResultSet对象没有属性错误

html = browser.page_source
textobj = BeautifulSoup(html,"html.parser")
text1=textobj.find_all('div', attrs={'class': 'vr_listing'})
for item in text1:
     foo=item.find_all('div', attrs={'class' : 'price'})
     price=foo.text.strip()
     print(price)
使用Python 3.7
不知道该怎么办。

如果您能提供您正在使用的链接,以便我们重现问题,那就太好了。但是你能试试这一行代码吗:

html = browser.page_source
textobj = BeautifulSoup(html,"html.parser")
prices = textobj.findAll('div', {'class':'price'}).text

for price in prices:
    print(price)

'''
text1=textobj.find_all('div', attrs={'class': 'vr_listing'})
for item in text1:
     foo=item.find_all('div', attrs={'class' : 'price'})
     price=foo.text.strip()
     print(price)
'''
在这里:

find_all()。如果希望在
项中有一个匹配的标记,请使用
项。查找(…)

 foo = item.find('div', attrs={'class' : 'price'})
 price = foo.text.strip()
否则在结果集上迭代:

 foos = item.find_all('div', attrs={'class' : 'price'})
 prices = [foo.text.strip() for foo in foos]
这是我的完整python脚本
 foos = item.find_all('div', attrs={'class' : 'price'})
 prices = [foo.text.strip() for foo in foos]