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

  • SEARCH
  • Home
  • 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 am trying to parse an XML file with python using lxml, but get
I am trying to parse an HTML table using lxml. While rows = outhtml.xpath('//tr/td/span[@class=boldred]/text()')
I have a function which connects to a url by httplib using lxml .
I want to parse HTML with lxml using XPath expressions. My problem is matching
I'm trying to do this (using lxml): //*[@id=32808345 or @id=33771423 or @id=15929470 or @id=33771117
I am trying to print a XML file using lxml and Python. Here is
I'm trying to parse an xml file using lxml. xml.etree allowed me to simply
I am using lxml to get a string from a web page. What do
I'm trying to parse a website's source to extract text inside using lxml library.
I'm trying to write a python script that modifies the contents of <script> tag

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.