我试图使用beautifulsoup刮取newegg的产品名称,描述,价格和图像 . 我有以下bs4.element.Tag类型,我想从标签中提取“src”链接 . 以下是我的标签:
df = <a class="itemImage" href="http://www.newegg.com/Product/Product.aspx?Item=N82E16875169194&cm_re=Samsung_edge-_-75-169-194-_-Product" id="img_75-169-194" title='Samsung Galaxy S7 Edge Dual SIM Unlocked Smart Phone, Dual Edge 5.5" AMOLED Display, black Color, 32GB Storage 4GB RAM International Version - No US Warranty'>\n<img alt='Samsung Galaxy S7 Edge Dual SIM Unlocked Smart Phone, Dual Edge 5.5" AMOLED Display, black Color, 32GB Storage 4GB RAM International Version - No US Warranty' src="http://images10.newegg.com/ProductImageCompressAll200/75-169-194-04.jpg" title='Samsung Galaxy S7 Edge Dual SIM Unlocked Smart Phone, Dual Edge 5.5" AMOLED Display, black Color, 32GB Storage 4GB RAM International Version - No US Warranty'/>\n</a>
我怎样才能提取出来
src="http://images10.newegg.com/ProductImageCompressAll200/75-169-194-04.jpg"
从这个标签?我试过了
df.attrs['src']
但我收到了Keyerror .
2 回答
src在img标签中:
哪个会给你:
在python引用中尝试正则表达式
https://docs.python.org/2/library/re.html
输出: