这样的事情应该这样做:a_tags=driver.find_elements_by_xpath("//div[@class='v1Nh3 kIKUG _bz0w']//a")hrefs=[a_tag.get_attribute('href') for a_tag in a_tags]for href in hrefs: driver.get(href) #...do whatever you need here
使用以下 CSS 选择器。driver=webdriver.Chrome()driver.get("https://www.instagram.com/bestmarketing.es/")allurls=[url.get_attribute('href') for url in driver.find_elements_by_css_selector(".v1Nh3.kIKUG._bz0w>a")]for url in allurls: driver.get(url)