'Scraping issue using BeautifulSoup and Selenium
I am starting coding for myself and I am blocked on a code line. Can you provide me some explications ?
I want to scrape informations from this div tag :
role = experience1_div('span', {'class' : 'mr1 t-bold'}) print(role)
Output :
[<span class="mr1 t-bold"> <span aria-hidden="true"><!-- -->Automation Engineer - Intern<!-- --></span><span class="visually-hidden"><!-- -->Automation Engineer - Intern<!-- --></span> </span>]
How can I get only the HTML text : "Automation Engineer - Intern"
I tried this function .get_text().strip() but it seems that the span tag is blocking my function....
Solution 1:[1]
This is the simplest technique to achieve your aim.
role = experience1_div.select_one('span.mr1.t-bold >span').get_text(strip=True) print(role)
Solution 2:[2]
I don't know what experience1_div is but to get all text use role.text
role = experience1_div.find('span', {'class' : 'mr1 t-bold'})
print(role.text)
output:
Automation Engineer - InternAutomation Engineer - Intern
To get text from the first nested span, use
role.span.text
or from the second nested span
role.contents[2].text
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jaibalaji |
| Solution 2 |
