想在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}但是我做錯了事,無法得到我的魔杖。請幫助我理解我的錯誤。
添加回答
舉報
0/150
提交
取消