Python-BeautifulSoup4-查找属性是name的标签
Refer to How to get an attribute value based on the name attribute. record for myself and share with you.
BeautifulSoup4中查找tag的常见方法是:
1 | '<div class="city">') soup = BeautifulSoup( |
然而,有时候我们会遇到一种奇葩情况,就是属性也叫name,如:
1 | '<div name="city">') soup = BeautifulSoup( |
这种情况若采用常规方法是无法运行的,需要换一种思路。
1 | "div", name="city") soup.find( |
正确的方法参考如下,将属性部分用dict的方式表示即可:
1 | '<META NAME="City" content="Austin">') soup = BeautifulSoup( |