このページ(http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I)のWebクローラーを作成して各ページの在庫リストを収集しました。まず最初に、私のコードは "Search Menu"の部分のドロップダウンメニューを操作することから始まりますが、反復中にページの読み込みと保持に問題があります。私がしたいのは、ページを読み込んで、ページのクロールアクションが完了するまでそのページを保持することです。Selenium Pythonを使用してページを読み込んだ後、特定のページを保持する方法はありますか?
以下は私のコードです:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import WebDriverException
from selenium.common.exceptions import StaleElementReferenceException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
from urllib import parse
from time import sleep
self.link = 'http://www.bobaedream.co.kr/cyber/CyberCar.php?gubun=I'
self.driver = webdriver.PhantomJS()
self.driver.set_window_size(1920, 1080)
self.driver.get(self.link)
self.wait = WebDriverWait(self.driver, 10)
def option2_menu_loaded(inDriver):
path = '//select[@id="level2_no"]'
return inDriver.find_element_by_xpath(path)
self.wait.until(option2_menu_loaded)
while True:
try:
select_option2_values = [
('%s' % o.get_attribute('text'), '%s' % o.get_attribute('value'))
for o
in Select(self.driver.find_element_by_css_selector("#level2_no")).options
if o.get_attribute('text') != '세부등급']
except (StaleElementReferenceException, NoSuchElementException):
print("=======Exception Found - Option2 Save=====")
self.driver.refresh()
self.driver.implicitly_wait(1.5)
continue
break
for option2 in select_option2_values:
self.csv.setCarTitle(ma, mo, de, option1[0], option2[0])
print(option2[0], option2[1])
self.driver.implicitly_wait(0.5)
while True:
try:
Select(self.driver.find_element_by_css_selector("#level2_no")).select_by_value(option2[1])
except (StaleElementReferenceException, NoSuchElementException):
print("=======Exception Found - Option2 Request=====")
self.driver.refresh()
self.driver.implicitly_wait(1.5)
self.driver.refresh()
continue
break
私は5行目の後に "self.wait.until(EC〜。)" のコードのいくつかのタイプを推測、 "self.wait.until(option2_menu_loaded)" かもしれません助けて。私はたくさん試しましたが、解決策を見つけることができません。
私はこれを解決するために手伝ってください。