0
Selenium Webdriverランタイムに問題があります。実際に私は10個のURLで配列を開き、いくつかのコンテンツをスクラップしています。Selenium Webdriverのパフォーマンス対時間
時間が経過してセレンが4番目のURLを開くと、非常に遅くなります...タスクを続行すると終了できません。実行時間を超過したためにpythonが処理を中断します。
最初のURLの擦り傷は1分、2番目の1〜2分、3番目の4分、...と分かります。
私はこの問題の回避策が必要です。私はipythonノートブック2.7を使用しています。
PS:別のタブでURLを開くと効果があると思いますか?
編集:これは私がブラウザを作成する方法である:
chromeOptions = webdriver.ChromeOptions()
prefs = {"profile.managed_default_content_settings.images":2,
"profile.default_content_setting_values.notifications" : 2,}
chromeOptions.add_experimental_option("prefs",prefs)
chromeOptions.add_argument("--window-position=0,0")
browser = webdriver.Chrome(chrome_options=chromeOptions)
これは、タスクは、アレイの各URLで実行されている。
browser.get(url)
lastHeight = browser.execute_script("return document.body.scrollHeight")
while True:
browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
newHeight = browser.execute_script("return document.body.scrollHeight")
if newHeight == lastHeight:
break
lastHeight = newHeight
start = 'Por '
end = ' com'
html_source = browser.page_source
soup = BeautifulSoup(html_source)
cl = soup.find_all('div', attrs={'class': 'cl'})
names = [None] * len(cl)
for i in range(len(cl)):
try: names[i] = re.search('%s(.*)%s' % (start, end), cl[i].text).group(1)
except: continue
photosof = list(set(names))