Filter HTML tags with python

Source: Internet
Author: User
Tags python script

Data is collected with ' <> ' HTML tags: <span class= ' wmojpqm2azpqma ' > Research <span class= ' WMOJPQM2AZHQMQ ' > The earliest and <span class= ' WmoJPQM2AzxQNw ' > A <span class= ' Wmojpqm2azdqoa ' > teaching as one of the modernization of <span class= ' Wmojpqm2azhqoa ' > Comprehensive <span class= ' WMOJPQM2AZHQMQ ' > Division from the Sex Provincial hospital
here as long as all band <> removal can be:
Dr = Re.compile (R ' <[^>]+> ', re. S) dd = Dr.sub (', Html ')
Complete Python script: The first function: Remove the scraping number from a field the second function: Remove all tags in Html

#!/usr/bin/env python #-*-coding:utf-8-*-import mysqldb import SYS import RE conn = Mysqldb.conn ECT (host= ' 127.0.0.1 ', user= ' user ', passwd= ' 123456 ', db= ' Hospital ', charset= ' utf8 ') cur = conn.cursor () def update_level (): Cur.execute ("Select Id,level from hospital where level like ' (%) '") for Row in Cur.fetchall (): Sid=row
        [0] Ii=re.sub (' (|\) ', ', row[1]) sql = "Update hospital set level=%s where id=%s" Print sid,ii param = [Ii,sid] Cur.execute (sql,param) def update_detail (): Dr = Re.compile (R ' <[^>]+> ', re. S) Cur.execute ("SELECT Id,details from hospital") for Row in Cur.fetchall (): did = Row[0] Detail=r
        OW[1] dd = dr.sub (', detail) sql= "Update Hospital set details=%s where id=%s" param = (dd,did)  Cur.execute (sql,param) print "Finished", did def Main (): #update_level () update_detail () if __name__ = = ' __main__ ': Main () 


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.