使用Python 2.7x从href标记提取字符串

使用Python 2.7x从href标记提取字符串,python,regex,python-2.7,beautifulsoup,Python,Regex,Python 2.7,Beautifulsoup,我目前正在使用Beautifulsoup4从HTML页面提取“a href”标记。我正在使用Beautifulsoup4中的find_all查询,它工作正常,并返回我正在寻找的“a href”标记。返回内容的示例如下: "<a href="manage/foldercontent.html?folder=Pictures" style="background-image: url(shares/Pictures/DefaultPicture.png)" target="content_wi

我目前正在使用Beautifulsoup4从HTML页面提取“a href”标记。我正在使用Beautifulsoup4中的find_all查询,它工作正常,并返回我正在寻找的“a href”标记。返回内容的示例如下:

"<a href="manage/foldercontent.html?folder=Pictures" style="background-image: url(shares/Pictures/DefaultPicture.png)" target="content_window" title="Vaya al recurso compartido Pictures">Pictures</a>"
req = urllib2.Request(example_url)
response = urllib2.urlopen(req)
soup = BeautifulSoup(response.read(), from_encoding=response.info().getparam('charset'))
for link in soup.find_all('a', href=True):
    # The below 'if' is to filter out only relevant 'a href' tags
    if "foldercontent.html?folder" in link['href']: 
        print link
这是否可能通过修改我搜索的内容实现,或者我必须在返回的字符串中运行正则表达式?

您可以使用:

[仅获取URL路径或查询字符串,或将查询字符串解析为其组成部分。

您可以使用:

[仅获取URL路径,或仅获取查询字符串,或将查询字符串解析为其组成部分

for link in soup.select('a[href*="foldercontent.html?folder"]'):