在某些网站(尤其是该https://www.sothebys.com/en/results)中,当您向下滚动页面时,更多链接可用,但是,不能通过漂亮的汤或硒来提取它们。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument("--test-type")
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get("https://www.sothebys.com/en/results")
urls=[]
for a in driver.find_elements_by_xpath('.//a'):
urls.append(a.get_attribute('href'))
urls
您能帮我提供代码还是建议我应该做什么?
答案 0 :(得分:0)
一些让您入门的东西:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Chrome()
driver.get("https://www.sothebys.com/en/results")
print(len(driver.find_elements_by_xpath('.//a')))
driver.find_element_by_xpath('.//body').send_keys(Keys.END)
time.sleep(2)
print(len(driver.find_elements_by_xpath('.//a')))
driver.find_element_by_xpath('.//body').send_keys(Keys.END)
time.sleep(2)
print(len(driver.find_elements_by_xpath('.//a')))
driver.close() # to close the browser
请注意,随着我们通过driver.find_element_by_xpath('.//body').send_keys(Keys.END)