我選擇了Selenium,因爲鏈接的hrefs是動態生成的,儘管通過bs4的某些方法會更受歡迎。這些JavaScript鏈接如何通過Selenium或BeautifulSoup遍歷?
我使用PhantomJS但試圖火狐以及
當試圖點擊一個鏈接,沒有任何反應。
例如,
url = 'http://www.achema.de/de/ausstellung/aussteller-und-produkte.html'
driver.get(url)
resultsBox = driver.find_element_by_css_selector('div[id="ix_result"]')
for tr in resultsBox.find_elements_by_tag_name('tr'):
link = tr.find_element_by_tag_name('a')
link.click()
# I've also tried:
# ActionChains(driver).move_to_element(link).click(link).perform()
你確定你迭代的集合有元素'a'嗎?您應該提供測試輸入以獲得更好的答案。 – Hamlett