Answer the question
In order to leave comments, you need to log in
How to parse article number from hyperlink?
I have the following hyperlink with the article number at the end of the url:
<a href="https://example.com/?p=5144" rel="bookmark"> example </a>
Answer the question
In order to leave comments, you need to log in
In any convenient way
Split
url = 'https://example.com/?p=5144'
page = url.split('?p=')[-1]
url = 'https://example.com/?p=5144'
page = url.replace('https://example.com/?p=', '')
import re
url = 'https://example.com/?p=5144'
page = re.search(r'\?p=(\d+)', url).group(1)
url = soup.find("a", class_="класс тега").get("href")
page = url.replace('https://example.com/?p=', '')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question