0

I'm trying scrape data about complaints on a website. Each complaint shows the time difference between the time complaint was posted and the current time (e.g. 10 hours ago, 2 days ago, etc.). I'm able to scrape that value but I need to get the exact date because the website only shows the date for old complaints.

enter image description here

I scrape the time difference (marked with yellow) with the following code:

url = 'https://www.sikayetvar.com/sikayetler?brand=bosch&page=1'
r = requests.get(url, headers={"User-Agent":"Mozilla/5.0"})
soup1 = bs(r.content, 'lxml')
dates = soup.find_all("span", {"class":"info-icn time-tooltip"})
print(dates[0].text)
1 saat önce

print(dates[0])
<span class="info-icn time-tooltip" data-placement="top" data-toggle="tooltip" title="03 Haziran 12:09"><span class="time-history">1 saat önce</span></span>

But, I need the actual date the complaint was posted (circled with red).

Thanks in advance for your tips and suggestions.

SonerY
  • 13
  • 2
  • try this, ``print(dates[0]['title'])`` https://stackoverflow.com/questions/2612548/extracting-an-attribute-value-with-beautifulsoup – sushanth Jun 03 '20 at 11:20
  • Thanks, it worked. I can't believe it is so simple. I tried many different things but sometimes we can't just see the obvious. – SonerY Jun 03 '20 at 11:55

1 Answers1

0

You can extract title attribute from the <span> tag.

For example:

import requests
from bs4 import BeautifulSoup

url = 'https://www.sikayetvar.com/sikayetler?brand=bosch&page=1'
soup = BeautifulSoup( requests.get(url, headers={"User-Agent":"Mozilla/5.0"}).content, 'html.parser' )

for title, t in zip(soup.select('article.card .card-title'), soup.select('article.card span.time-tooltip')):
    print('{:<70}{}'.format(title.text, t['title']))

Prints:

Bosch Bir Aydır Ürün Gönderimi Yapmıyor                               03 Haziran 12:09
Bosch'ta  Buzdolabı Sebzeliği Su Sorunu                               03 Haziran 12:02
Bosch Teslim Edilmeyen Ürün                                           02 Haziran 22:04
Kgn56vw30n Model Buzdolabı                                            02 Haziran 20:42
Bosch Satarken İstediğiniz İle Göndeririz Deyip Göndermiyorlar.       02 Haziran 18:02
Bosch Marka Bulaşık Makinesi Punto Kaynağı Sorunu!                    02 Haziran 16:52
Bosch 288₺'lik Ampul Ücreti                                           02 Haziran 16:44
Bosch Ürün Teslimatı Yapılmıyor                                       02 Haziran 16:31
Bosch Buzdolabının Sesinde Sorun Var                                  02 Haziran 16:01
Bosch Kırık Ürün - Para İadesi Yok                                    02 Haziran 16:01
Bosch Bulaşık Makinesi Hiç Memnun Kalmadım                            02 Haziran 15:46
Bosch Teslim Edilmeyen Ürün ve Para İadesi Yapılmayan Ürün            02 Haziran 14:24
Bosch Buzdolabı Sürekli Bozuluyor                                     02 Haziran 13:27
Bosch Hasarlı Teslim Edilen Ürün Sorunsalı                            02 Haziran 12:32
Bosch Müşteri Hizmetleri İşini Yapmıyor!                              02 Haziran 12:29
Bosch Servis Karmaşası...                                             02 Haziran 12:14
Andrej Kesely
  • 168,389
  • 15
  • 48
  • 91