# -*- coding:utf-8 -*-
import requests
import lxml.html
etree = lxml.html.etree
def get_jdshopname(url):
header = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36"}
response = requests.get(url, headers=header)
html = etree.HTML(response.text)
plist = html.xpath('//ul[@class="parameter2 p-parameter-list"]/li/text()') #获取商品详情
if plist: #针对除海囤全球
plist.append(''.join(html.xpath('//div[@class="name"]/a/text()'))) #店铺名称
else: #针对海囤全球
plist = html.xpath('//ul[@class="parameter2"]/li/text()')
if plist:
plist.append(''.join(html.xpath('//strong[@clstag="shangpin|keycount|product|dianpu_oversea"]/a/text()'))) # 店铺名称
else:
plist.append(''.join(html.xpath('//div[@class="name"]/a/text()'))) #店铺名称
#return plist
return plist[len(plist)-1] #返回列表最后一个元素
'''
s = get_jdshopname("https://item.jd.com/65794452723.html")
print(s)
'''
分类