【发布时间】:2015-03-11 20:12:57
【问题描述】:
此代码用于从 html 网页获取链接,但我想让它只给我带有某些单词的链接。
例如,只有在 URL 中有这个词的链接:"www.mywebsite.com/word"
我的代码:
import httplib2
from BeautifulSoup import BeautifulSoup, SoupStrainer
http = httplib2.Http()
status, response = http.request('http://www.mywebsite.com')
for link in BeautifulSoup(response, parseOnlyThese=SoupStrainer('a')):
if link.has_key('href'):
print link['href']`
【问题讨论】:
标签: python url web beautifulsoup httplib2