I started working on some website scraping projects and I stumbled accros some difficulties selecting a second tag within the same parent tag. I've tried using google but i still couldn't cleary understand it.
My code looks like this:
url = 'url to site'
content = requests.get(url).text
soup = BeautifulSoup(content, 'lxml')
car_add = soup.find('div', class_='offer-wrapper')
ad_title = car_add.find('h3', class_='lheight22 margintop5').a.strong.text
ad_price = car_add.find('p', class_='price').text
ad_location = car_add.find('td', class_='bottom-cell').div.p.small.span.text
ad_time_and_location = car_add.find('td', class_='bottom-cell').div.p
print(ad_time_and_location.prettify())
This prints out the following:
<p class="lheight16">
<small class="breadcrumb x-normal">
<span>
<i data-icon="location-filled">
</i>
Otopeni
</span>
</small>
<small class="breadcrumb x-normal">
<span>
<i data-icon="clock">
</i>
09:25
</span>
</small>
</p>
What I want to do is access the string '09:25' but when I type:
ad_location = car_add.find('td', class_='bottom-cell').div.p.small.span.text
Then it automatically defaults to the first text tag.
I've tried using the select() method but it gave me an empty list. Could anyone help me with this ?
Thank you!