Use Beautiful Soup in Python to Extract HTML Meta Keywords and Description

Use explicit attrs filtering for meta tags:

1
2
md_desc = soup.find('head').find('meta', attrs={'name': 'description'})['content']
md_keywords = soup.find('head').find('meta', attrs={'name': 'keywords'})['content']

You can also iterate all meta tags and filter by attribute names.

记录并分享
Built with Hugo
Theme Stack designed by Jimmy