开发者

BeautifulSoup - extracting attribute values

开发者 https://www.devze.com 2022-12-10 11:01 出处:网络
If Beautiful Soup gives me an anchor tag like this: <a class=\"blah blah\" id=\"blah blah\" href=\"link.html\"></a>

If Beautiful Soup gives me an anchor tag like this:

<a class="blah blah" id="blah blah" href="link.html"></a>

How would I retrieve the value of the href开发者_运维问答 attribute?


If you already have the anchor, grab the href attribute like this:

href = anchor["href"]


link.get('href')

in which 'link' is the name of your 'a' tag

0

精彩评论

暂无评论...
验证码 换一张
取 消