Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3335014
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:58:10+00:00 2026-05-17T23:58:10+00:00

I am using lxml’s xpath function to retrieve parts of a webpage. I am

  • 0

I am using lxml’s xpath function to retrieve parts of a webpage. I am trying to get contents of a <font> tag, which includes html tags of its own. If I use

//td[@valign="top"]/p[1]/font[@face="verdana" and @color="#ffffff" and @size="2"]

I get the right amount of nodes, but they are returned as lxml objects (<Element font at 0x101fe5eb0>).

If I use

//td[@valign="top"]/p[1]/font[@face="verdana" and @color="#ffffff" and @size="2"]/text()

I get exactly what I want, except that I don’t get any of the HTML code which is contained within the <font> nodes.

If I use

//td[@valign="top"]/p[1]/font[@face="verdana" and @color="#ffffff" and @size="2"]/node()

if get a mixture of text and lxml elements! (e.g. something something <Element a at 0x102ac2140> something)

Is there anyway to use a pure XPath query to get the contents of the <font> nodes, or even to force lxml to return a string of the contents from the .xpath() method, rather than an lxml object?

Note that I’m returning a list of many nodes from the XPath query so the solution needs to support that.

just to clarify… i want to return something something <a href="url">inside</a> something from something like…

<font face="verdana" color="#ffffff" size="2"><a href="url">inside</a> something</font>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T23:58:10+00:00Added an answer on May 17, 2026 at 11:58 pm

    I’m not sure I understand — is this close to what you are looking for?

    import lxml.etree as le
    import cStringIO
    content='''\
    <font face="verdana" color="#ffffff" size="2"><a href="url">inside</a> something</font>
    '''
    doc=le.parse(cStringIO.StringIO(content))
    
    xpath='//font[@face="verdana" and @color="#ffffff" and @size="2"]/child::*'
    x=doc.xpath(xpath)
    print(map(le.tostring,x))
    # ['<a href="url">inside</a> something']
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to do this (using lxml): //*[@id=32808345 or @id=33771423 or @id=15929470 or @id=33771117
Using lxml in python I created this xpath syntax htmlPage.xpath(/html/body//a/text()) It gets me all
Using C# .NET 3.5 and WCF, I'm trying to write out some of the
Using C# and System.Data.SqlClient, is there a way to retrieve a list of parameters
Using lxml.objectify like so: from lxml import objectify o = objectify.fromstring(<a><b atr='someatr'>oldtext</b></a>) o.b =
I am using lxml to manipulate some existing XML documents, and I want to
I'm using lxml to programatically build HTML and I need to include a custom
I am using lxml to read through an xml file and change a few
I am using lxml and Python for writing XML files. I was wondering what
I'm using lxml to create an XML file from scratch; having a code like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.