我正在使用Selenium和beautifulsoap抓取网页以获取详细信息,我想将15个类别链接收集到一个变量中,然后从该单独类别中再次获取链接并将其存储在另一个变量中。
我想列出下一个按钮的所有链接,但没有得到类名
def get_link_by_text(text):
"""Find link in the page with given text"""
element = driver.find_element_by_link_text(text.strip())
return element.get_attribute("href")
def get_list_by_class_name(class_name="main_image "):
"""Get list of text in all element by class_name"""
element_list = []
try:
all_elements = driver.find_elements_by_class_name(class_name)
element_list = [x.text for x in all_elements if len(x.text) > 0]
except (NoSuchElementException, WebDriverException) as e:
print(e)
return element_list
category_links = {x: get_link_by_text(x)
for x in get_list_by_class_name('list_title')}