It's Corinne's question! Python question

Asked 2 years ago, Updated 2 years ago, 53 views

Find selenium find_element as xpath and use the corresponding variable (?) Is there any way to find the ahref attribute in this? First of all, it doesn't make sense, but for an example of a question, as shown below.?

e = driver.find_element(By.XPATH, '//*[@id="account"]/a')
soup = BeautifulSoup(driver.page_source, 'html.parser')
d = soup.find(e)('a')['href']

python crawling scraping

2022-09-20 11:07

1 Answers

Yes, that's how you do it.

from bs4 import BeautifulSoup

html_doc = '<aid="pickme" href="https://example.com">Find me Yes</a>'
soup = BeautifulSoup(html_doc, 'html.parser')
ele = soup.select_one('#pickme')

print(ele['href']) // https://example.com


2022-09-20 11:07

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.