Jua*_*nti 5 python beautifulsoup
如何使用BeautifulSoup查找指向特定域的页面中的所有链接?
使用SoupStrainer,
from BeautifulSoup import BeautifulSoup, SoupStrainer
import re
# Find all links
links = SoupStrainer('a')
[tag for tag in BeautifulSoup(doc, parseOnlyThese=links)]
linkstodomain = SoupStrainer('a', href=re.compile('example.com/'))
Run Code Online (Sandbox Code Playgroud)
编辑:官方文档中的修改示例.