Chuyển đến nội dung chính

Convert HTML Entities to normal text

import htmlentitydefs as html
import re

def unescapeHTML(str):
    str = re.sub(r"<.+?>|</.+?>", '', str)
    str = re.sub(r'&#(\d+);', lambda m: unichr(int(m.group(1))).encode('utf-8'), str)
    str = re.sub(r'&(\w+);', lambda m: unichr(html.name2codepoint[m.group(1)]).encode('utf-8'), str)

    return str

======================================
#using beautifulsoup
import re, copy
from BeautifulSoup import BeautifulSoup

hexentityMassage = copy.copy(BeautifulSoup.MARKUP_MASSAGE)
hexentityMassage = [(re.compile('&#x([^;]+);'), lambda m: '&#%d' % int(m.group(1), 16))]

def unescapeHTML2(str):
    str = re.sub(r"<.+?>|</.+?>", '', str)
    try:
        return BeautifulSoup(str, convertEntities=BeautifulSoup.HTML_ENTITIES, markupMassage=hexentityMassage).contents[0].string
    except:
        return str

Nhận xét

Bài đăng phổ biến từ blog này

Windows 10 enable long file/folder path

Windows 10 enable long file/folder path Registry Import Enabling Long Paths Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\FileSystem] "LongPathsEnabled"=dword:00000001 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem] "LongPathsEnabled"=dword:00000001 Enable via group policy editor Local Computer Policy -> Computer Configuration -> Administrative Templates -> System -> FileSystem -> Double click Enable Win32 long paths and select Enabled

[Solved] Adobe Premiere Pro CC 2015 has stopped on Windows 10 x64 (card AMD)

First you can check yours graphic card fully support Adobe Premiere Pro CC 2015 at here: http://blogs.adobe.com/premierepro/2013/05/improved-gpu-support-in-adobe-premiere-pro-cc.html If you open "Configure Switchable Graphics", you'll see the adobe premiere pro.exe has been locked. By default, it only run on Intel graphics, so you cant change or unlock this. To make your Adobe Premiere Pro CC 2015 run on AMD Graphics card, just rename file Adobe Premiere Pro.exe into Adobe Premiere Pro CC.exe After rename, run application again, and open Configure Switchable Graphics and choose High Performance. See this thread for more information: https://community.amd.com/thread/167905

Tạo SVN Server & import project lên svn

Hướng dẫn tạo svn repository, cấu hình apache & đẩy dự án lên SVN Đối với một vài dự án nhỏ bạn không được cấp svn, bạn không thể sử dụng những dịch vụ svn cung cấp miễn phí: Google code, bitbucket,... lúc đó điều đầu tiên nảy sinh trong đầu các bạn là cài đặt svn server trên máy mình để tiện sử dụng. Điều kiện, máy bạn cần cài đặt apache & svn - Trên Windows: các bạn có thể cài Xampp, wampserver hoặc apache riêng & TortoiseSVN - Trên Mac OSX: apache & svn đã có mặc định Ở đây mình hướng dẫn sử dụng trên hệ điều hành MacOSX ( do mình sử dụng máy Mac) Bước 1 . Tạo thư mục SVN. Để có thể add nhiều project vào svn, các bạn nên tạo một thư mục cha ví dụ: svn. Ở đây mình tạo thư mục svn với đường dẫn /Data/svn Bước 2 . Tạo file /Data/svn/.svn-policy-file [groups] team1 = longhoanggiang, giangnh [/] * = [symfony2jobeet:/] @team1 = rw ngongocquynh = r * =   Dấu * ở đây có nghĩa là tất cả anonymous user (ẩn danh) sẽ chỉ có quyền đọc (read). User l...