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 9102711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T01:26:48+00:00 2026-06-17T01:26:48+00:00

Im trying to parse an html output from a url call but i found

  • 0

Im trying to parse an html output from a url call but i found myself struggling on how i could get it working.

Im using the following code:

    import urllib2
    import base64 as b64
    import lxml.html as LH

    request = urllib2.Request('http://%s%s' % (fInput[1], fInput[2]))
    base64string = b64.encodestring('%s:%s' % (fInput[3], fInput[4])).replace('\n', '')
    request.add_header("Authorization", "Basic %s" % base64string)
    response = urllib2.urlopen(request)
    html = response.read()
    root = LH.fromstring(html)
    sibling_content = lambda x: [b.getparent().getnext().text_content() for b in root.cssselect("td b:contains('{0}')".format(x))]
    fields = ['groupList','namelist']


    for result in zip(*[sibling_content(field) for field in fields]):
        print result

The result i have when i print the output is:

('Admins', '\nme\nmyself\nirene')('guests', '\nhin\nhinself\nbacon')

The output that would fit for what i need is have an array like this, so i could insert it into a database:

['Admins', 'me','myself','nirene'],['guests', 'hin','hinself','bacon']

FOllowing, im sending the Html returned by the HTTP request:

<BODY bgcolor="#dddddd">
   <TABLE bgcolor="#dddddd" border="1">
      <TR>
         <TD valign="top"><B>MainList</B></TD>
         <TD>
            <TABLE>
               <TR>
                  <TD>
                     <TABLE bgcolor="#dddddd" border="1">
                        <TR>
                           <TD valign="top"><B>groupList</B></TD>
                           <TD>Admins</TD>
                        </TR>
                        <TR>
                           <TD valign="top"><B>namelist</B></TD>
                           <TD>
                              <TABLE>
                                 <TR>
                                    <TD>me</TD>
                                 </TR>
                                 <TR>
                                    <TD>myself</TD>
                                 </TR>
                                 <TR>
                                    <TD>irene</TD>
                                 </TR>
                              </TABLE>
                           </TD>
                        </TR>
                     </TABLE>
                     <TABLE bgcolor="#dddddd" border="1">
                        <TR>
                           <TD valign="top"><B>groupList</B></TD>
                           <TD>guests</TD>
                        </TR>
                        <TR>
                           <TD valign="top"><B>namelist</B></TD>
                           <TD>
                              <TABLE>
                                 <TR>
                                    <TD>hin</TD>
                                 </TR>
                                 <TR>
                                    <TD>hinself</TD>
                                 </TR>
                                 <TR>
                                    <TD>bacon</TD>
                                 </TR>
                              </TABLE>
                           </TD>
                        </TR>
                     </TABLE>
                  </TD>
               </TR>
            </TABLE>
         </TD>
      </TR>
   </TABLE>
</BODY>

Any ideas of how i could get this working?

Thanks in advance.

  • 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-06-17T01:26:49+00:00Added an answer on June 17, 2026 at 1:26 am

    Using xpath:

    root=LH.fromstring(html)
    [t.xpath('.//td[not(contains(.,"\n"))]/text()')
        for t in root.xpath('.//table[@bgcolor="#dddddd"]')]
    

    out:

    [['Admins', 'me', 'myself', 'irene'], ['guests', 'hin', 'hinself', 'bacon']]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to parse a html doc using some code I found from this
I'm trying to parse the following HTML from the following URL: http://md5.rednoize.com/?q=fbade9e36a3f36d3d676c1b808451dd7 The code:
I'm trying to parse an html output file from a program called mirdeep. I
I have been trying to get a number from a html string, but I
I am trying to parse html using BeautifulSoup to try and extract the webpage
i'm trying to parse an html page and get the first occurrence of a
I'm trying to Parse the following HTML pages using BeautifulSoup (I'm going to parse
I'm trying to parse some returned html (from http://www.google.com/movies?near=37130 )to look for currently playing
I'm trying to return JSON output from a Laravel route. Here's my route: Route::get('main-contact-count',
I am trying to extract table content from a html file using HTML::TableExtract. My

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.