为了账号安全,请及时绑定邮箱和手机立即绑定

从表中提取(Scrapy)

从表中提取(Scrapy)

郎朗坤 2021-05-09 11:14:30
想在python2中使用scrapy进行表解析时寻求帮助,这是我的表: 链接到表 我需要获取<td>标签的值。尝试使用下一个python代码:rows = resp.xpath('//*[@id="Vorlage_Infobox_Unternehmen"]')if not rows:    rows = resp.xpath('.//*[@id="Vorlage_Infobox_Unternehmen"]//table')try:    if rows:        extract = lambda row, path: row.xpath(path).extract_first().strip()        if '<th>' in str(rows):            infobox = {extract(row, 'string(./th)'): extract(row, 'string(./td)') for row in rows}        elif '<tr>' in str(rows):            infobox = {extract(row, 'string(./td[1])'): extract(row, 'string(./td[2])') for row in rows}        elif '<table>' in str(rows):            infobox = {extract(row, 'string(./th)'): extract(row, 'string(./td)') for row in rows}        else:            infobox = {extract(row, 'string(./table/tbody/tr[1])'): extract(row, 'string(./td[1])') for row in rows}但是我做错了事,无法得到我的魔杖。请帮助我理解我的错误。
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 133 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号