Найти - Пользователи
Полная версия: аналз HTML
Начало » Центр помощи » аналз HTML
1
natalija96
Помогите пожалуйста решить задание - в инпут вводишь в одну линию хтмл код, а питон ситает сколько смволов в коде.


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

Спасибо!
crow
 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>')

lxml возможно придется устанавливать
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB