Search for all links ending in a given phrase.
Example check?uri= : https://validator.w3.org/check?uri=

Display all links or links of a region ending in check?uri= using regular expressions. But I do not know how to implement. I asked almost the same question, but I was not given a specific answer.

Closed due to the fact that the essence of the issue is incomprehensible by the participants Wiktor Stribiżew , andreymal , Alexey Shimansky , αλεχολυτ , апр Apr 13 '17 at 19:36 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • 2
    You should show developments and specify the issue. For example, where do search: in the file with the list url or in html document. Because The choice of the processing tool depends on it. For a file it will be enough to read and filter line by line. For the web page, pull out with the html / xml parser or regular (a parser is preferable to regulars). And add an example of the data from which you want to get the necessary pieces - gil9red
  • You have already been answered in the deleted question - andreymal

2 answers 2

 from re import findall TEXT = '''http://ya.ru/check?uri= qwe http://google.ru/check?uri= ? http://mail.ru''' urls = 'http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+' result = [url for url in findall(urls, TEXT) if url.rstrip().endswith('check?uri=')] print(result) # ['http://ya.ru/check?uri=', 'http://google.ru/check?uri='] 
  • "url for url in findall (urls, TEXT)" I don’t understand why url, or something should be inserted there? - Danya Gololobov
  • then start with the basics - vadim vaduxa
  • Why is nothing displayed on my screen? I added print (url) and nothing happens. from re import findall TEXT = '' '...' '' urls = 'http [s]?: // (?: [a-zA-Z] | [0-9] | [$ -_ @. & +] | [! * (),] | (?:% [0-9a-fA-F] [0-9a-fA-F])) + 'for url in findall (urls, TEXT): if url. strip (). endswith ('check? uri ='): print (url) - Dania Gololobov
  • list generators - vadim vaduxa
  • Sorry, I'm very stupid, I tried to do something, but I can't do anything. from re import findall TEXT = '' '...' '' urls = 'http [s]?: // (?: [a-zA-Z] | [0-9] | [$ -_ @. & +] | [! * (),] | (?:% [0-9a-fA-F] [0-9a-fA-F])) + 'for url in findall (urls, TEXT): if url. strip (). endswith ('check? uri ='): for i in range (b): print (i) Please correct my clumsy code. I can not solve this problem for a week. - Danya Gololobov

I think it's easier to use the standard string endswith function:

 >>> 'https://validator.w3.org/check?uri='.endswith('check?uri=') >>> True