在此处输入图像描述, 请参考随附的图片图像。我正在尝试获取时间戳和以下 10 #content,如图所示以及下面代码中的预期输出,但是我无法获取“40 分钟前”类型的文本。相反,我得到的是这种格式的“08-04-2021 16:48:34”。
from bs4 import BeautifulSoup
import requests
URL="https://trends24.in/india/"
html_text=requests.get(URL)
soup= BeautifulSoup(html_text.content,'lxml')
results = []
job_elem=soup.findAll(attrs={'class': 'trend-card'})
for j in job_elem:
print(j.find('h5').get_text())
for i in soup.select('#trend-list li'):
d = dict()
d[i.a.text] = ''
try:
val = i.select_one('.tweet-count').text
except:
val = "NA"
finally:
d[i.a.text] = val
results.append(d)
print(d)
**Output:**
08-04-2021 16:48:34
08-04-2021 15:54:30
08-04-2021 15:01:07
...
{'#AskNivetha': 'NA'}
{'#TikaUtsav': 'NA'}
{'#VakeelSaabFestivalBegins': '62K'}
...
**expected output :**
40 minutes ago
{'#AskNivetha': 'NA'}
{'#TikaUtsav': 'NA'}
{'#VakeelSaabFestivalBegins': '62K'}
{'ANMOL SUSHANT': '33K'}
{'#TheBigBull': 'NA'}
{'#IPL2021': '73K'}
{'nidra ley uv creations': '64K'}
{'Chief Ministers': 'NA'}
{'B. True 48MP Camera': 'NA'}
{'conan': '51K'}
1 hour ago
{'#AskNivetha': 'NA'}
{'#VakeelSaabFestivalBegins': '50K'}
{'NIDRA LEY UV CREATIONS': '59K'}
{'#SecretOfHappyLiving': 'NA'}
{'#MeditateToRaiseWillpower': 'NA'}
{'#HappinessMantra': 'NA'}
{'ANMOL SUSHANT': 'NA'}
{'Tika Utsav': 'NA'}
{'Chief Ministers': 'NA'}
{'conan': '46K'}
另外我正在尝试获取时间戳,然后是 10 个#content 标题。如随附的屏幕截图所示。