爬取的数据非html格式,网页爬虫 - python爬虫,爬取到的HTML源码是一种编码格式展示的内容,但是具体处理数据的适合就取不到这个值。...

python爬虫,爬取到的HTML源码是一种编码格式展示的内容,但是具体处理数据的适合就取不到这个值。

练习爬取的网页:

https://detail.tmall.com/item...

代码的目的是获取对应手机的型号:

def handle_starttag(self, tag, attrs):

if tag == 'tr' and not self.finish:

for variable, value in attrs:

if variable == 'class' and value == 'tm-tableAttrSub':

self.target_tr = True

if tag == 'th' and self.target_tr and not self.finish:

self.processing = 'th'

if tag == 'td' and self.target_tr and self.target_th and not self.finish:

# print 'value:',value

self.processing = 'td'

def handle_data(self, data):

if self.processing == 'th' and data.find('型号') > -1 and not self.finish and self.target_tr:

self.target_th = True

self.processing = ''

if self.processing == 'td' and not self.finish and self.target_tr and self.target_th:

self.finish = True

self.target_th = False

self.target_tr = False

self.temp = data

self.processing = ''

print 'phoneName', data

获取到的HTML代码片段:

型号& nbsp;& #32418;& #31859;& #25163;& #26426;3

(原内容直接复制就被转码展示了,可以将&后的空格去掉)

最后的输出:

phoneName 3

但是期望的输出应该是:

phoneName 红米手机3

请教各位大大,怎么将获取到的html代码片段中的正确内容复制到data中呢?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值