Python regular expression fix for Web site article font not uniform resolution method

Source: Internet
Author: User
There are defined fonts in the large frame of the website, including font size and color, which may be copied from other websites when the user publishes the article, and the copying process retains the font description information. When the article is displayed on the page, the font defined in the article is used by default and the global font defined in the large frame is displayed if the font does not exist in the article. Therefore the content of the website will appear very messy, some article font is very big, some article font is very small, not beautiful. It's good to be unified!

I'm not familiar with HTML and CSS, and I don't know if I can set the font content defined in the article to expire.

Stupid people have stupid way, unified change the article, the user's definition of the font are all deleted! Ha ha! If done by hand, this is a very heavy task, to first preview the page, if not unified to modify the font, fortunately, the editor has a "clear format" option, select Text, click on OK, and then save ... And it's troublesome.

If only to modify the font, the most convenient way is to directly modify the database, from the database to extract the article, delete and font-related tags, and then write back to the database.

Specifically looked at the HTML reference manual, the definition of fonts there are two ways:

1. The label is used, for example:

The code is as follows:




This is a paragraph.



This is another paragraph.



This method is not recommended for use

2. Use the style definition, for example:

The code is as follows:



This was a paragraph with some text in it. This was a paragraph with some text in it. This was a paragraph with some text in it. This was a paragraph with some text in it.



As long as you delete the definition part of the font, you can replace it with Python's regular expression module, without pressure:

The code is as follows:


def format (data):
"' Delete all font tags and style tags '
p = re.compile (r ' | | Style=\ ". *?\" ')
ret = P.sub (", data)
IF RET! = data:
Return Retelse:
Return None


Python should be aware of updating data methods when dealing with database related operations, which can be referenced in this article: http://www.cnblogs.com/ma6174/archive/2013/02/21/2920126.html
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.