使用BeautifulSoup进行网页抓取时无法在网站中获取所有div

时间:2020-02-12 04:05:17

标签: python html css beautifulsoup

我想知道是否有人可以解决这个site上所有类名为“ ZVAUHZqh”的div的问题。我想通过BeautifulSoup通过该div类名称中的URL刮取所有图像,这是一个很新的东西。下面是我的代码。当我运行代码时,它告诉我有36张图像,每个图像应有208个div。不仅如此,它还会打印出没有背景图像可以在网站上为我在数据中创建的列表中的34个项目提供图像。对于为什么它不收集页面上的所有div以及为什么说明background-image设置为none的任何帮助,将不胜感激。非常感谢!

# importing required libraries
import requests
from bs4 import BeautifulSoup
import pandas as pd

# target URL to scrap
url = "https://www.tripadvisor.com/Hotel_Review-g30242-d83948-Reviews-Crowne_Plaza_Crystal_City_Washington_D_C-Arlington_Virginia.html#/media/83948/?albumid=106&type=2&category=106"

#request for the website
website = requests.get(url)

#parse the website data and store into 'data'
data = BeautifulSoup(website.content, 'html.parser')

#find all divs with the specified class name
image_data = data.find_all('div', attrs={"class": "ZVAUHZqh"})

#print all of the images in the list
print('Total number of images: ', len(image_data))

#print out all of the images
 for image in image_data:
     print(image)

0 个答案:

没有答案