Q:

how to search for a phrase using regular expressions?

please help to fix the script.
import urllib
import re
import os
import pprint

import requests
import bs4

stringHtml = urllib.request.urlopen('http://forum.saransk.ru/user/2018-sergey-kalinin/').read().decode('utf-8')
#print(stringHtml)
stringPattern = 'url\suid"\shref="http://vkontakte.ru/id10550933"'
result = re.search(stringPattern, stringHtml)
if result:
    print(result.group())
else:
    print('no result') 

the problem is that the script displays a "no result". compiled regular expression correctly. please help find an error

A:

Why don't you use bs4 imported?
If you want print href attribute of the a element with class uid and url, you can use select method (which accept css selector).
import urllib.request

import bs4

stringHtml = urllib.request.urlopen('http://forum.saransk.ru/user/2018-sergey-kalinin/').read()#.decode('utf-8')
soup = bs4.BeautifulSoup(stringHtml)
for a in soup.select('a.url.uid'):
    print(a.get('href'))

# If you want to check whether the a tag with `href="http://vkontakte..."` exist,
#   use following lines instead.
# (CSS Selector `a.url.uid[href="..."]` does not work with bs4.
#  bs4 supports most commonly-used CSS selectors, not all of them)
#print(any(a.get('href') == 'http://vkontakte.ru/id10550933'
#      for a in soup.select('a.url.uid')))

output:
http://vkontakte.ru/id10550933

