How to Use Python regular expressions to identify landlords

Source: Internet
Author: User

Do you know how to use Python regular expressions to identify the landlord? If you want to know how to use a Python regular expression to identify the specific operations of the landlord's actual application solution, you can click the following article to learn about it. I hope you will gain some benefits.

Identify the owner:

Post code snippet: <! -- Tianya treasure chest -->

 
 
  1. <Script>
  2. Var chrType = "public ";
  3. Var intAuthorId = "";
  4. Var chrAuthorName = "GreyHouse ";
  5. Var chrTitle = "[light and shade records] A trip to flea Europe ";
  6. Var chrItem = 'travel ';
  7. Var intItem = '0 ';
  8. Var intArticleId = "191157 ";
  9. Var tAuthor = 'greyhouse ';
  10. </Script>

Use the following Python regular expression to find the owner:

 
 
  1. rereg_louzhu = re.compile('.*chrAuthorName = "(.*?)"; ' 

If mat is set to reg_louzhu.match (the html line of the webpage source code), mat. groups () [0] is the name of GreyHouse.

Identify the starting position of a post

After continuing to analyze html, we found that Tianya replies generally use the author's information column as the starting point of the post, so the post end is before the next author's information column.

 
 

  1. <TABLE cellspacing = 0 border = 0 bgcolor = f5f9fa
    Width = 100%> <TR> <td width = 100 ALIGN = RIGHT
    VALIGN = bottom> </TD> <font size =-1
    Color = green> <br> <center> author: <
    Href = "/browse/Listwriter. asp? Vid = 11288815 & vwriter =
    Go shopping with tanks & idwriter = 0 & key = 0 "target = _ blank> go shopping with tanks </a>

The above is an introduction to Python Regular Expressions and identifying the starting position of a post.

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.