Найти - Пользователи
Полная версия: регулярные выражения- все внутри тега
Начало » Python для новичков » регулярные выражения- все внутри тега
1
Panter7777
Добрый день.
Помогите разобраться, мне нужно вытащить все между тегами <code>…</code>
Делаю так:
content = re.findall(r'<code> (.*?) </code>', _file)
но в ответ вижу
pill
Не видя содержимого “_file”, точно сказать сложно. )
Но может дело в пробелах?
>>> data = '<code>12345</code>'
>>> re.findall(r'<code> (.*?) </code>', data)
4: []
>>> re.findall(r'<code>(.*?)</code>', data)
5: ['12345']
Panter7777
Я наверное не правильно обьяснил, вообщем есть страница
<!-- BEGIN pager -->
<code>

<form method="GET" action="">
<table class="records" cellspacing="0" cellpadding="4" border="1" width="100%">
<tr>
<td colspan="7">
<p>Записей на странице: <input name="page_size" size=5> <input type="submit" name="changepagesize" value=" >> "></p></form>
</td>
</tr>
<tr><td colspan="7">&nbsp;</td></tr>

<tr bgcolor="#e0e0e0" align="center" valign="middle">
<th>ID наряда:</th>
<th>Дата создания:</th>
<th>Адрес:</th>
<th>Тип:</th>
<th>Склад:</th>

<th>Создатель:</th>
<th>Подробно:</th>
</tr>

<tr bgcolor="#f0f0f0" align="left">
<td>2097033770</td>
<td><nobr>30.05.11 09:02</nobr></td>
<td><nobr>вул. Маршала Малиновського, 25г, 1 под.</nobr></td>

<td>close</td>
<td><span style='color:red;'>Сдан</span></td>
<td>Вознюк Вячеслав</td>
<td><a href="../problems/view/2097033770" onclick="window.open('../problems/view/2097033770', '_new', 'resizeble=1, scrollbars=1, width=550, height=700, toolbars=0'); return false"><img src="../../img/detail.gif" border="0" title="Подробно"/></a></td>
</tr>

......................................

</table>
</code>
<!-- END pager -->
я ее открываю:
 
filename = dirname(page.path)+"/problems_naryad.any"
_file = open(filename, 'r').read()

content = re.findall(r'<code>(.*?)</code>', _file)

print content
Мне нужнем код(вся таблица) что внутри тега <code>…</code>
pill
re.findall(r'<code>(.*?)</code>', data, re.DOTALL)
По умолчанию “.” - ловит совпадения только до конца строки…
Panter7777
Получилось спасибо большое.
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