When I run the code below,
link = f"https://www.ambalajstore.com/kategori/bardak-tabak?siralama=fiyat:asc&stoktakiler=1&tp=1"
response = requests.get(link)
html_icerigi = response.content
corba = BeautifulSoup(html_icerigi,"html.parser")
for a in corba.find_all("div",{"class":"paginate-content"}):
x = corba.find_all("div",{"class":"paginate-content"})
print(x)
I get results:
[<div class="paginate-content">
<a class="paginate-element-active" href="javascript:void(0);">1</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&stoktakiler=1&tp=2">2</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&stoktakiler=1&tp=3">3</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&stoktakiler=1&tp=4">4</a>
<a href="javascript:void(0);">..</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&stoktakiler=1&tp=13">13</a>
</div>]
What I need is just the number 13 (last number) in the last line (<a href="/category/cup-plate?order=price:asc&stock=1&tp=13">13</a>)
Can you help me on how to do this?
>Solution :
You can do it like this
corba.find("div",{"class":"paginate-content"}).find_all('a')[-1].text
this will give you the text content of the last item(13 in your case)