我有这个:
<a class = "__cf_email__"
data-cfemail = "c2a3aca6b0a7a3eca1ada382a5afa3abaeeca1adaf"
href = "http://www.cloudflare.com/email-protection">[email protected]</a>
我需要获取此字符串c2a3aca6b0a7a3eca1ada382a5afa3abaeeca1adaf
。有任何想法吗?不知道我是怎么尝试上课但是可以得到字符串
autor = soup.findAll("a", {"class": "__cf_email__"}, limit = 1)
答案 0 :(得分:4)
Tag
的属性可通过__getitem__
方法访问。换句话说,"you can access a tag's attributes by treating the Tag object as though it were a dictionary."
>>> autor = soup.find("a", {"class": "__cf_email__"})
>>> print autor["data-cfemail"]
'c2a3aca6b0a7a3eca1ada382a5afa3abaeeca1adaf'
答案 1 :(得分:0)
您是否有意获得data-cfemail
的{{1}}属性?