Relevant links what? Their attribute is HREF? Link display text? Perhaps something like:
from BeautifulSoup import BeautifulSoup, SoupStrainer
import re
import urllib2
doc = urllib2.urlopen("http://somesite.com").read()
links = SoupStrainer('a', href=re.compile(r'^test'))
soup = [str(elm) for elm in BeautifulSoup(doc, parseOnlyThese=links)]
for elm in soup:
print elm
This will grab the HTML content somesite.comand then parse it with BeautifulSoup, looking only for links whose HREF attribute begins with a “test”. He then creates a list of these links and prints them.
, -, documentation.