Python 如何在漂亮的soap中从给定代码中获取href属性

Python 如何在漂亮的soap中从给定代码中获取href属性,python,beautifulsoup,Python,Beautifulsoup,我想从给定列表中获取所有的href属性。如何从给定代码中提取href。因为div&a标记彼此相邻div.a是可能的 from selenium import webdriver from bs4 import BeautifulSoup as Bs import time driver = webdriver.Chrome(executable_path=r'C:\Users\kaka\PycharmProjects\chromedriver.exe') google_get = drive

我想从给定列表中获取所有的href属性。如何从给定代码中提取href。

因为
div
&
a
标记彼此相邻
div.a
是可能的

from selenium import webdriver
from bs4 import BeautifulSoup as Bs
import time

driver = webdriver.Chrome(executable_path=r'C:\Users\kaka\PycharmProjects\chromedriver.exe')

google_get = driver.get('https://www.google.com/?q=nlp techniques')
google_search = driver.find_element_by_xpath(
    '/html/body/div[1]/div[3]/form/div[2]/div[1]/div[3]/center/input[1]').click()
time.sleep(1)
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
time.sleep(2)
soup = Bs(driver.page_source, 'html.parser')
time.sleep(1)
link = soup.find_all('div', {'class': 'yuRUbf'})
for lnk in link:
    print(lnk)
link = [div.a['href'] for div in 
        soup.find_all('div', attrs={'class' : 'yuRUbf'})]