需求:根据关键之找到货号的TAG,并爬取数值
方法如下:
'''第一步:使用正则 :re.compile() 包含关键字 ‘货号’ '''
'''第二步:公式 soup.find(tag类型,text =pattern) 备注:用两次,第一次 使用 class_= 定位 '''
'''第三部:货号的数据是在下一个 span , 所以直接用 next_sibling 下个兄弟节点。 '''
'''第四部:使用文本 get_text() 提取'''
pattern = re.compile('货号')
sku_code = soup.find('div', class_='ma-d-uli p').find('span', text=pattern).next_sibling.get_text()
print('7.商品货号', sku_code)