刮标签值

时间:2018-05-31 17:08:52

标签: python-3.x web-scraping beautifulsoup

我想问一下,我可以用beautifulsoup刮取标签的价值: 我想得到一个img src:

<img class="product-pic" src="//cdn.shopify.com/s/files/1/1385/4109/products/Beef_Patties_grande_41a52a6f-1d85-499c-be1d-06ecb318c2ad_large.jpg?v=1469212539" alt="Beef Burgers">

我想刮掉src的价值。即。

//cdn.shopify.com/s/files/1/1385/4109/products/Beef_Patties_grande_41a52a6f-1d85-499c-be1d-06ecb318c2ad_large.jpg?v=1469212539
我正在做的是:

containers[0].find("img").next_element.next_element.next_element.next_element.next_element.next_element

但我没有得到预期的输出,我得到的是:

<a href="/collections/beef/products/beef-burgers">Beef Burgers</a>

任何帮助将不胜感激,谢谢

1 个答案:

答案 0 :(得分:0)

我得到了我的问题的答案,我所要做的就是简单:

img = containers[0].find("img",{"class":"product-pic"})
src = img["src"]

输出:

'//cdn.shopify.com/s/files/1/1385/4109/products/Beef_Patties_grande_41a52a6f-1d85-499c-be1d-06ecb318c2ad_large.jpg?v=1469212539'