Найти - Пользователи
Полная версия: lxml parse
Начало » Python для новичков » lxml parse
1
ashimano
Помогите мне пожалуйста. Уже очень много тем посмотрел, но ничего не выходит.
from lxml.html import parse 
page = parse('http://ria.ru/religion/all.html').getroot() 
fc = page.find_class('b-list')  
print (fc) 

Когда так пишу, выдает мне тип элемента и его размер, если я не ошибаюсь.
А как сделать так, чтобыон мне вывел все то, что содержится в нем?
Я понимаю, что надо цикл сделать
for row in fc:
но у меня проблема с выводом информации идет.

pyuser
Оно?
from lxml.html import parse, tostring
page = parse('http://ria.ru/religion/all.html').getroot() 
fc = page.find_class('b-list') 
print(*(tostring(e) for e in fc), sep="\n")
papuas
http://lxml.de/lxmlhtml.html
.text_content():
Returns the text content of the element, including the text content of its children, with no markup.

>>> type(fc)
<type 'list'>

Ваш fc контейнер содержит в себе список из нескольких контейнеров.

<div class="b-list">
     <div class="b-list__item">
     <a href="/religion/20160608/1444696851.html">
     <div class="b-list__item-story">
     <div class="b-list__item-announce">
     <div class="b-list__item-info">
</div>

>>> for x in fc:
...     print x.text_content()
...

но я думаю проще достать контент из них используя Xpath
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