Python regular Expressions fix Web site article font resolution _PYTHON

Source: Internet
Author: User

The Web site's large frame has defined fonts, including font size and color, and so on, when the user published the article may be copied from other sites, copy the process also 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 under the large frame is displayed if the font does not exist in the article. So the content of the site will appear very messy, some articles font is very large, some articles 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 that is defined in the article to be invalidated.

Stupid people have a stupid way, unified modify the article, the user's definition of the font deleted all! 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 the text, click on the OK, and then save ... It's also troublesome.

If you only 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.

A special look at the HTML reference manual, there are two ways to define the font:

1. Use <font> label, for example:

Copy Code code as follows:

<p>
<font size= "2" face= "Verdana" >
This is a paragraph.
</font>
</p>

<p>
<font size= "3" face= "Times" >
This is another paragraph.
</font>
</p>


This method is not recommended for use

2. Use the style definition, for example:

Copy Code code as follows:

<p style= "Font-family:verdana;font-size:80%;color:green" >
This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it. This is a paragraph with some text in it.
</p>

Just remove the definition part of the font and replace it with Python's regular expression module without pressure:

Copy Code code as follows:

def format (data):
"Delete the font label and style label All" "
p = re.compile (R ' <font. *?>|</font>|style=\ ". *?\")
ret = P.sub (', Data ')
If RET!= data:
Return Retelse:
Return None

Python to handle database-related operations should be careful to update the data method, you can refer to 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.