Ваш код, кажется, в основном в порядке и просматривает их для меня.К сожалению, все объекты не продаются, поэтому все они дают мне ошибки, и я не могу произвести ожидаемое поведение.Я думаю, что вы должны реализовать try:
и except:
, finally:
запускается независимо от того, что произошло, и я не думаю, что вы захотите обновлять каждые 2 секунды XD.Вам также не нужно continue
в конце, это ничего не делает.Код
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
import ssl
from twilio.rest import Client
from twilio.rest import TwilioRestClient
from bs4 import BeautifulSoup as soup
urls = ['https://www.hubzu.com/property/90089436968-730-Trillium-Ln-Lilburn-GA-30047',
'https://www.hubzu.com/property/90016097522-225-Marriott-Ave-Schenectady-NY-12304',
'https://www.hubzu.com/property/90016098285-17-Spring-Meadows-Dr-Ormond-Beach-FL-32174']
browser = webdriver.Chrome()
# Start URL switch tryouts.
while True:
for url in urls:
browser.get(url)
# This is the process i need all urls to do.
time.sleep(2)
address = soup(browser.page_source, 'html.parser').find('span', {'class': 'h1'}).text
try:
propertyprice = browser.find_element_by_css_selector('span.current-bid')
currentBidText = propertyprice.text
WebDriverWait(browser, 90000).until(
EC.text_to_be_present_in_element((By.CSS_SELECTOR, 'span.current-bid'), currentBidText)
)
except Exception as e:
print("an error occurred on property {}:\n{}".format(address.strip(), e))
finally:
pass
# print("+++ Send notifications.")
# account_sid = "***"
# auth_token = "***"
# client = Client(account_sid, auth_token)
#
# PhoneNumber1 = "+***"
# PhoneNumber2 = "+***"
# print("+ Send notifications to: ", PhoneNumber1, " and ", PhoneNumber2)
#
# sendTo1 = "{\"binding_type\":\"sms\",\"address\":\"" + PhoneNumber1 + "\"}"
# print("+ sendTo1: ", sendTo1)
# sendTo2 = "{\"binding_type\":\"sms\",\"address\":\"" + PhoneNumber2 + "\"}"
# print("+ sendTo2: ", sendTo2)
#
# notify_service_sid = "***"
# notification = client.notify.services(notify_service_sid).notifications.create(
# body='There has been a change at: '+address,
# to_binding=[sendTo1, sendTo2]
# )
#
# print("+ Notification SID: ", notification.sid)
#
# print("+++ Exit.")
Перебирает все свойства, и пример вывода для меня:
an error occurred on property 730
Trillium Ln
Lilburn, GA 30047:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"span.current-bid"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
an error occurred on property 225 Marriott Ave
Schenectady, NY 12304:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"span.current-bid"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
an error occurred on property 17 Spring Meadows Dr
Ormond Beach, FL 32174:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"span.current-bid"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
an error occurred on property 730
Trillium Ln
Lilburn, GA 30047:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"span.current-bid"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
an error occurred on property 225 Marriott Ave
Schenectady, NY 12304:
Message: no such element: Unable to locate element: {"method":"css selector","selector":"span.current-bid"}
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab),platform=Windows NT 10.0.14393 x86_64)
и так далее в бесконечном цикле ...