0
0
000pssp2021-12-10 04:16:51
Python
000pssp, 2021-12-10 04:16:51

How can I display the index 1, 2, etc. link?

Is it somehow possible to display each link separately by index, or in another way?

import requests
from bs4 import BeautifulSoup

url =  requests.get(f"https://all-avito.ru/ru/phone/89039123444")
soup = BeautifulSoup(url.content, 'lxml')

for link in soup.find_all('a'):
    keys = ["ru/item/"]
    for key in keys:
        url = link.get("href")
        url = f'https://all-avito.ru/{url}'
        if key in str(url):
            print(url)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question