美空每周十大模特网页:http://www.moko.cc/ranking/talent.html
以下代码仅供学习参考使用!
from lxml import etree
html = etree.HTML(r.text)
tname = html.xpath('//div[@class="personData"]/span/text()')[0]
tsrc = html.xpath('//div[@class="firstPerson"]/img/@src')[0]
ul = html.xpath('//ul[@class="otherPerson"]')
oname = ul[0].xpath('./li/a/div[1]/span/text()')
osrc = ul[0].xpath('./li/a/img/@src')
info = '{}"top":1,"name":"{}","img":"{}"{}'.format('[{',tname,tsrc,'}')
for i in range(9):
info += '{}"top":{},"name":"{}","img":"{}"{}'.format(',{',i+2,oname[i],osrc[i],'}')
info += ']'
with open('output.json', 'w', encoding='utf-8') as fp:
json.dump(info, fp, ensure_ascii=False)
还没有评论,快来发表第一个评论!