
Hi, If I have this as my HTML <html> <head></head> <body> <a> <b>city</b>My City <b>state</b>My State </a> </body> </html> and I have this as my code s = '<html><head></head><body><a><b>city</b>City<b>state</b>State</a></body>' s1 = etree.HTML(s) How can I get (find or findall or something else) "My City" and "My State" using lxml? Thanks in advance. Silent

btw - I have tried get next() and 'following-sibling' - they do not work. following-sibing gives me an error prefix 'following-sibling' not found in prefix map getnext() on the first "b" element should return "My City", but it returns the "state" element. SS On Sat, Feb 16, 2013 at 6:29 PM, Sandip Shah <sandipshah@vthrive.com> wrote:
Hi,
If I have this as my HTML
<html> <head></head> <body> <a> <b>city</b>My City <b>state</b>My State </a> </body> </html>
and I have this as my code
s = '<html><head></head><body><a><b>city</b>City<b>state</b>State</a></body>' s1 = etree.HTML(s)
How can I get (find or findall or something else) "My City" and "My State" using lxml?
Thanks in advance.
Silent

Hi Sandip, Try this:
from lxml import etree s = '<html><head></head><body><a><b>city</b>City<b>state</b>State</a></body>' s1 = etree.HTML(s) [ b.tail for b in s1.xpath('/html/body/a/b')] ['City', 'State']
Is it solve your problem? Regards, Piotr 2013/2/17 Sandip Shah <sandipshah@vthrive.com>
btw - I have tried get next() and 'following-sibling' - they do not work.
following-sibing gives me an error
prefix 'following-sibling' not found in prefix map
getnext() on the first "b" element should return "My City", but it returns the "state" element.
SS
On Sat, Feb 16, 2013 at 6:29 PM, Sandip Shah <sandipshah@vthrive.com>wrote:
Hi,
If I have this as my HTML
<html> <head></head> <body> <a> <b>city</b>My City <b>state</b>My State </a> </body> </html>
and I have this as my code
s = '<html><head></head><body><a><b>city</b>City<b>state</b>State</a></body>' s1 = etree.HTML(s)
How can I get (find or findall or something else) "My City" and "My State" using lxml?
Thanks in advance.
Silent
_________________________________________________________________ Mailing list for the lxml Python XML toolkit - http://lxml.de/ lxml@lxml.de https://mailman-mail5.webfaction.com/listinfo/lxml

Hi Piotr, Yes, that does solve my problem. I should have read the tutorial thoroughly. I somehow missed the 'tail' function. Thanks a lot for your guidance. Sandip On Sun, Feb 17, 2013 at 2:43 PM, Piotr Owcarz <powcarz@gmail.com> wrote:
Hi Sandip,
Try this:
from lxml import etree s = '<html><head></head><body><a><b>city</b>City<b>state</b>State</a></body>' s1 = etree.HTML(s) [ b.tail for b in s1.xpath('/html/body/a/b')] ['City', 'State']
Is it solve your problem?
Regards, Piotr
2013/2/17 Sandip Shah <sandipshah@vthrive.com>
btw - I have tried get next() and 'following-sibling' - they do not work.
following-sibing gives me an error
prefix 'following-sibling' not found in prefix map
getnext() on the first "b" element should return "My City", but it returns the "state" element.
SS
On Sat, Feb 16, 2013 at 6:29 PM, Sandip Shah <sandipshah@vthrive.com>wrote:
Hi,
If I have this as my HTML
<html> <head></head> <body> <a> <b>city</b>My City <b>state</b>My State </a> </body> </html>
and I have this as my code
s = '<html><head></head><body><a><b>city</b>City<b>state</b>State</a></body>' s1 = etree.HTML(s)
How can I get (find or findall or something else) "My City" and "My State" using lxml?
Thanks in advance.
Silent
_________________________________________________________________ Mailing list for the lxml Python XML toolkit - http://lxml.de/ lxml@lxml.de https://mailman-mail5.webfaction.com/listinfo/lxml
participants (2)
-
Piotr Owcarz
-
Sandip Shah