下面是我使用的代码:
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
driver=webdriver.Chrome()
driver.get('https://www.bonhams.com/auctions/25281/?category=results#/!')
while True:
next_page_btn =driver.find_elements_by_xpath("//*[@id='lots']/div[2]/div[5]/div/a[10]/div")
if len(next_page_btn) <1:
print("no more pages left")
break
else:
titles = driver.find_elements_by_xpath("//*[@class='firstLine']")
titles = [title.text for title in titles]
print(titles)
element = WebDriverWait(driver,5).until(expected_conditions.element_to_be_clickable((By.ID,'lots')))
driver.execute_script("return arguments[0].scrollIntoView();", element)
element.click()
下面是我得到的输出。Python一次又一次地重复/加载这个输出(我认为它这样做了33次??)。你知道吗
['Hong Kong Watches 2.0', '', 'OMEGA. A Very Fine And Rare Limited Edition
Yellow Gold Chronograph Bracelet Watch, Commemorating the Apollo 11 Space
Mission And The Successful Moon Landing in 1969', '', '', '', 'ROLEX. TWO
SETS OF SHOWCASE DISPLAYS, MADE FOR ROLEX RETAILERS IN 1970s', '', 'ROLEX.
TWO SETS OF RARE SHOWCASE DISPLAYS, MADE FOR ROLEX RETAILERS IN 1980s',
'', 'PATEK PHILIPPE. A SET OF THREE RARE LIMOGES PORCELAIN AND ENAMEL
DISHES', '', 'Bvlgari/MAUBOUSSIN. TWO SETS OF CUFFLINKS', '',
'BOUCHERON/MONTBLANC. TWO SETS OF CUFFLINKS', '', 'PATEK PHILIPPE. TWO
SETS OF CUFFLINKS', '', 'Jaeger-LeCoultre. A Gilt Brass Table Clock With
8-Days Power Reserve and Alarm', '', 'Cartier & LeCoultre. A group of
three gilt brass table clocks (Alarm/Alarm Worldtime/Engraved dial)', '',
'Jaeger-LeCoultre. A Gilt Brass Table Clock With 8-Days Power Reserve',
'', 'Reuge. A Gold Plated Musical Automaton Open Face Pocket Watch with
Alarm', '', 'Imhof. An Attractive Gilt Brass Table Clock With Polychrome
Enamel Dial', '', 'Vacheron Constantin. A Large Polished Metal Perpetual
Calendar Wall Clock']
['Hong Kong Watches 2.0', '', 'OMEGA. A Very Fine And Rare Limited Edition
Yellow Gold Chronograph Bracelet Watch, Commemorating the Apollo 11 Space
Mission And The Successful Moon Landing in 1969', '', '', '', 'ROLEX. TWO
SETS OF SHOWCASE DISPLAYS, MADE FOR ROLEX RETAILERS IN 1970s', '', 'ROLEX.
TWO SETS OF RARE SHOWCASE DISPLAYS, MADE FOR ROLEX RETAILERS IN 1980s',
'', 'PATEK PHILIPPE. A SET OF THREE RARE LIMOGES PORCELAIN AND ENAMEL
DISHES', '', 'Bvlgari/MAUBOUSSIN. TWO SETS OF CUFFLINKS', '',
'BOUCHERON/MONTBLANC. TWO SETS OF CUFFLINKS', '', 'PATEK PHILIPPE. TWO
SETS OF CUFFLINKS', '', 'Jaeger-LeCoultre. A Gilt Brass Table Clock With
8-Days Power Reserve and Alarm', '', 'Cartier & LeCoultre. A group of
three gilt brass table clocks (Alarm/Alarm Worldtime/Engraved dial)', '',
'Jaeger-LeCoultre. A Gilt Brass Table Clock With 8-Days Power Reserve',
'', 'Reuge. A Gold Plated Musical Automaton Open Face Pocket Watch with
Alarm', '', 'Imhof. An Attractive Gilt Brass Table Clock With Polychrome
Enamel Dial', '', 'Vacheron Constantin. A Large Polished Metal Perpetual
Calendar Wall Clock']
不需要
selenium
库来废弃数据。还可以使用requests
和BeautifulSoup
库获取所有页面数据。你知道吗首页o/p:
打开browser network选项卡并单击next按钮,您将看到JSON响应数据,如![enter image description here](https://i.stack.imgur.com/VND74.png)
相关问题 更多 >
编程相关推荐