I just want to use regex to retrieve all elements which has "//" in my HTML string, and I follow the answer from this question: Using BeautifulSoup to find a HTML tag that contains certain text
And then I code a similar one:
from BeautifulSoup import BeautifulSoup
import re
html_text = \
"""
<html>
<!--<![endif]-->
<head>
<link rel="stylesheet" href="//abc.com/xyz" />
<meta rel="stylesheet" href="//foo.com/bar" />
</head>
</html>
"""
soup = BeautifulSoup(html_text)
for elem in soup(text=re.compile(r'//')):
print elem
I expect that I would have the result like:
//abc.com/xyz
//foo.com/bar
But I receive nothing. I don't know why their test case works but mine, is there any error or did I miss something in my script?