Форум сайта python.su
Помогите пожалуйста решить задание - в инпут вводишь в одну линию хтмл код, а питон ситает сколько смволов в коде.
Your task:
Program takes in input a one-line html website code containing nothing but 2-column table
Program calculates the sum of number in whole 2nd row
Example:
input: <html><body><table><tr><td>Item1<td>10</tr><tr><td>Item2<td>20</tr><body></html>
output: 30
Спасибо!
Офлайн
from lxml import html def clc(txt): txt = html.fromstring(txt) a = txt.xpath('/html/body/table/tr[1]/td[2]')[0].text b = txt.xpath('/html/body/table/tr[2]/td[2]')[0].text return int(a)+int(b) clc('<html><body><table><tr><td>Item1<td>10</tr><tr><td>Item2<td>20</tr><body></html>')
Офлайн