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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:28:34+00:00 2026-05-15T16:28:34+00:00

I need to extract the meta keywords from a web page using Python. I

  • 0

I need to extract the meta keywords from a web page using Python. I was thinking that this could be done using urllib or urllib2, but I’m not sure. Anyone have any ideas?

I am using Python 2.6 on Windows XP

  • 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-15T16:28:34+00:00Added an answer on May 15, 2026 at 4:28 pm

    lxml is faster than BeautifulSoup (I think) and has much better functionality, while remaining relatively easy to use. Example:

    52> from urllib import urlopen
    53> from lxml import etree
    
    54> f = urlopen( "http://www.google.com" ).read()
    55> tree = etree.HTML( f )
    61> m = tree.xpath( "//meta" )
    
    62> for i in m:
    ..>     print etree.tostring( i )
    ..>
    <meta http-equiv="content-type" content="text/html; charset=ISO-8859-2"/>  
    

    Edit: another example.

    75> f = urlopen( "http://www.w3schools.com/XPath/xpath_syntax.asp" ).read()
    76> tree = etree.HTML( f )
    85> tree.xpath( "//meta[@name='Keywords']" )[0].get("content")
    85> "xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,b
    eginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading
     style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide"
    

    BTW: XPath is worth knowing.

    Another edit:

    Alternatively, you can just use regexp:

    87> f = urlopen( "http://www.w3schools.com/XPath/xpath_syntax.asp" ).read()
    88> import re
    101> re.search( "<meta name=\"Keywords\".*?content=\"([^\"]*)\"", f ).group( 1 )
    101>"xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql, ...etc...
    

    …but I find it less readable and more error prone (but involves only standard module and still fits on one line).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract images from a FB fan page. I'm able to read
I need to extract pure text form a random web page at runtime, on
I need to extract some information from not very complicated HTML pages in web.
I need to extract the path info using Path.GetFileName() , and this function doesn't
I need to extract some text from a string, then replace that text with
I need to extract TIFF images from a bunch of multi-page PDF files from
I need to extract only the last row from a multi-line string using regular
How can I extract a page's title and meta description using the PHP Simple
Need to extract .co.uk urls from a file with lots of entries, some .com
I need to extract a value from a hidden HTML field, have somewhat figured

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.