【发布时间】:2021-03-25 17:10:15
【问题描述】:
我试图在 booking.com 上抓取酒店的图片。 如果我需要获取酒店的所有图片,我可以点击网页上的任何图片。 下面是html内容
<a data-id="88516347" data-thumb-url="https://cf.bstatic.com/images/hotel/max500/885/88516347.jpg" href="https://cf.bstatic.com/images/hotel/max1024x768/885/88516347.jpg" target="_blank" class="bh-photo-grid-item bh-photo-grid-photo3 active-image " style="background-image: url(https://cf.bstatic.com/images/hotel/max500/885/88516347.jpg);" onclick="return false;" title="The sunrise or sunset as seen from the apartment or nearby ">
<img src="https://cf.bstatic.com/images/hotel/max500/885/88516347.jpg" class="hide" alt="The sunrise or sunset as seen from the apartment or nearby ">
</a>
如果我单击图像,它将打开一个带有幻灯片的模式。 有谁知道如何通过 php Goutte 获取它?
我得到了一个关于这个的 python 示例。 https://github.com/basophobic/booking_scraper/blob/ec4382dd00970df0dab4b4df5d67143f9bbc2b21/web_scrapping.py
# click on the first image to open the image carousel
driver.find_element_by_class_name('bh-photo-grid-item').click()
# find the number of images for every hotel
tmp1 = driver.find_element_by_class_name('bh-photo-modal-caption-left').text
tmp = tmp1.split()
img_number = int(tmp[2])
print(img_number)
accommodation_fields['images'] = list()
# loop through every image to save the link
for image in range(img_number-1):
img_href = driver.find_element_by_class_name('bh-photo-modal-image-element').find_element_by_tag_name('img').get_attribute('src')
#print(img_href)
accommodation_fields['images'].append(img_href)
driver.find_element_by_class_name('bh-photo-modal-image-element').click()
print("Total images are: " + str(img_number-1))
但我不知道将其转换为 php 的 Goutte。 谢谢你。问候。
【问题讨论】:
标签: php web-scraping scrape goutte