Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

url split with beautifulsoup

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&amp;stoktakiler=1&amp;tp=2">2</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&amp;stoktakiler=1&amp;tp=3">3</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&amp;stoktakiler=1&amp;tp=4">4</a>
<a href="javascript:void(0);">..</a>
<a href="/kategori/bardak-tabak?siralama=fiyat:asc&amp;stoktakiler=1&amp;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&amp;stock=1&amp;tp=13">13</a>)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading