I'm sorry for the amateur question, but since I have no knowledge of regular expressions (I searched, but I was confused because there were many symbols), let me ask you a question.

"/ youtube/a-san/today"
"/ youtube/b-san/today"
"/ youtube/c-san/today"

Suppose you have a website with three urls built in, like. systematically

"/ youtube/*/today"

I think it has a structure like this, but how can I extract it as a regular expression (compile?) Using BeautifulSoup?

elems = soup.find_all (href = re.compile ("/ youtube/*/today"))

Then, I think that [] has come out.

  • Answer # 1

    What about below?

    elems = soup.find_all (href = re.compile ("/youtube/.*/today"))


    for el in elems:
        new_tag = soup.new_tag ('link href = "/ youtube/unknown/today"')
        el.replace_with (new_tag)

Related articles