0

Having trouble extracting the url from the background picture on this website. This picture refreshes every 5 minutes, changing the url so as far as I am aware I am forced to use this website, refresh every 5 minutes and grab this url. Ultimately, I am trying to grab this image every 5 minutes to create a video. I am able to navigate to the Div that I need, but when I am trying to split the string, I get errors about it not being a string. when is use print(type(divreq)) I get a bs4.element.Tag.

import time
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = "https://camera.deckchair.com/emporium-hotel-brisbane-australia"
options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome(options=options)
driver.get(url)
time.sleep(3)
page = driver.page_source
driver.quit()
soup = BeautifulSoup(page, 'html.parser')
divreq = soup.find('div',class_='image')
print(divreq)

my output is:

<div _ngcontent-ptg-1="" class="image" style='background-image: url("//api.deckchair.com/v1/viewer/image/610a5f61a95c310001bf67ba?width=1280&amp;height=720&amp;resizeMode=fill&amp;gravity=Auto&amp;quality=90&amp;panelMode=false&amp;format=jpg"); background-position: 50% 50%;'> </div>

The information I am trying to get is:

api.deckchair.com/v1/viewer/image/610a5f61a95c310001bf67ba

with the 610a5f61a95c310001bf67ba changing every 5 mintues.

0

2 Answers 2

1

using selenium, you can use get_attribute

driver.get(url)
time.sleep(3)
page = driver.page_source
attr_value = driver.find_element_by_css_selector("div.image").get_attribute('style')
print(attr_value)
Sign up to request clarification or add additional context in comments.

Comments

0

This code will search string between image/ and ?

import re
x = re.search(r'(?<=image/).+(?=\?)', divreq).group()
print(x)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.