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

Ask A Question

Stats

  • Questions 528k
  • Answers 528k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Did you take a look at regular expressions? Although, for… May 16, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer name is an attribute included for scripting backwards compatibility and… May 16, 2026 at 10:53 pm
  • Editorial Team
    Editorial Team added an answer Try creating the link on the subscriber. Run this on… May 16, 2026 at 10:53 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I need extract data from a string. Heres an example: Mozilla/5.0 (Macintosh; U; PPC
I've a web page that that can be used to upload files. Now I
I need to extract and decode barcodes and text from images. Is there any
I need to extract all the emails that show up as autocomplete entries in
I need to extract the extract this string as 2 document example test(s): testing
I need to extract the email address out of this mailbox string. I thought
I need to be able to split a string that contains email's From information.
I have a JSON multi-level response that I need to deserialize and from the
I encountered many sites including stackoverflow.com whose page source do not show META tags
I have a text where I need to: to extract the whole paragraph under

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.