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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:51:04+00:00 2026-05-15T10:51:04+00:00

hi all I’m trying to extract the META description from a webpage using libxml

  • 0

hi all I’m trying to extract the “META” description from a webpage using libxml for python. When it encounters UTF chars it seems to choke and display garbage chars. However when getting the data via a regex I get the unicode chars just fine. Am I doing something wrong with libxml?

thanks

''' test encoding issues with utf8 '''

from lxml.html import fromstring
from lxml.html.clean import Cleaner
import urllib2
import re

url = 'http://www.youtube.com/watch?v=LE-JN7_rxtE'
page = urllib2.urlopen(url).read()


xmldoc = fromstring(page)
desc = xmldoc.xpath('/html/head/meta[@name="description"]/@content')
meta_description = desc[0].strip()

print "**** LIBXML TEST ****\n" 
print meta_description


print "**** REGEX TEST ******"
reg = re.compile(r'<meta name="description" content="(.*)">')
for desc in reg.findall(page):
  print desc

OUTPUTS:

**** LIBXML TEST ****

My name is Hikakin.<br>I'm Japanese Beatboxer.<br><br>HIKAKIN Official Blog<br>http://ameblo.jp/hikakin/<br><br>ãã³çã³ãã¥<br>http://com.nicovideo.jp/community/co313576<br><br>â»å¾¡ç¨ã®æ¹ã¯Youtubeã®ã¡ãã»ã¼ã¸ã¾ã...
**** REGEX TEST ******
My name is Hikakin.&lt;br&gt;I'm Japanese Beatboxer.&lt;br&gt;&lt;br&gt;HIKAKIN Official Blog&lt;br&gt;http://ameblo.jp/hikakin/&lt;br&gt;&lt;br&gt;ニコ生コミュ&lt;br&gt;http://com.nicovideo.jp/community/co313576&lt;br&gt;&lt;br&gt;※御用の方はYoutubeのメッセージまた...
  • 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-15T10:51:05+00:00Added an answer on May 15, 2026 at 10:51 am

    Does this help?

    xmldoc = fromstring(page.decode('utf-8'))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All I'm trying to understand the obejctive C object runtime process From the Object
All, I'm inserting some text from a textarea in a mySQL database. I'm using
ALL, I am trying to read the value of 1.5 from the initialization file
All, I am just trying to get the zpipe demo working using dev-c++ where
All, If I run a query like the following: $qry = Select wrong_column from
All, How can I bind the array of drop down list items returned from
all. We're trying to get some intersect collisions working, but the problem experience is
All programs that I develop utilize the default Windows Design template: Besides from changing
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I am building a small site using PHP. In the site, I receive

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.