【发布时间】:2019-07-19 20:51:31
【问题描述】:
我正在过滤出现在本网站的固定收益产品:https://yubb.com.br/investimentos/renda-fixa?investment_type=cdb&months=3&principal=10000000.0&sort_by=minimum_investment
基本上,该页面有一些卡片,我想知道每个页面出现了多少张卡片。比如类型选择cdb,3个月,显示16张卡片,但再输入月份或产品类型,可能会出现较少的卡片。
现在,我知道查看“investmentCardContainer__footer”会显示多少页,这是一个类,但卡片的数量看起来像是样式,我不知道如何使用 selenium webdriver 找到它。查找函数。
这是我正在寻找的提示:
它的想法是获取此数量的卡片并在循环中使用它来获取聚合在向量中的卡片信息。
vetor = ["cdb","lca","lci"]
dataset_boxes =[]
now = time.time()
for i in vetor:
options = Options()
options.add_argument('--headless')
url = 'https://yubb.com.br/investimentos/renda-fixa?investment_type={}&months=12\
&principal=1000000.0&sort_by=net_return'.format(i)
driver = webdriver.Chrome("C:\\Users\\yourpath\\Desktop\\PYTHON\\chromedriver.exe",options=options)
driver.get(url)
time.sleep(1)
num_pages = driver.find_element_by_class_name("investmentCardContainer__footer").text
list_pages = Convert(num_pages)
last_page = int(list_pages[len(list_pages)-3])
driver.quit()
for j in range(1,last_page+1):
url2 = 'https://yubb.com.br/investimentos/renda-fixa?collection_page={}&investment_type={}&months=12\
&principal=1000000.0&sort_by=net_return'.format(j,i)
driver = webdriver.Chrome("C:\\Users\\yourpath\\Desktop\\PYTHON\\chromedriver.exe",options=options)
driver.get(url2)
num_boxes = driver.find_element_by_class_name("investmentCardContainer__body").text
list_boxes = Convert(num_boxes)
dataset_boxes.append(list_boxes)
driver.quit()
print('idk')
later = time.time()
difference = int(later - now)
print('Processo finalizado em {} segundos.'.format(difference))
【问题讨论】:
-
请检查带有 html 的第二个链接。
标签: python html selenium web-scraping