How can I use BeautifulSoup to search for all links on a page pointing to a specific domain?

How can I use BeautifulSoup to search for all links on a page pointing to a specific domain?

+4
source share
1 answer

Use 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/')) 

Edit: Modified example from white paper.

+7
source

Source: https://habr.com/ru/post/1299605/


All Articles