Hongmu Notes
Home Summary of pitfalls Commonly used regular filters for locomotive collection
Summary of pitfalls

Commonly used regular filters for locomotive collection

Commonly used regular filters for locomotive collection

In order to obtain a standard content, you must work hard on collection! Write the collection rules.

My measure of standard content:

Each paragraph is <p></p>

No redundant HTML tags and irrelevant characters

How to extract data

Select regular extraction and fill in the combined result <p>[Parameter 1]</p>

Some content does not have p tags at the beginning and end. Line breaks are done with br tags, so we need to create p tags.

Data processing

Step 1: Remove content irrelevant to the text, such as advertisements, comments, etc.

Regular <header>[\s\S]*?</header>|<!--.*?-->| |Rule 4|Rule 5 is replaced by empty

If published to some free platforms, some HTML special characters will not be converted. Just add '|&.*?;' at the end to filter out the last special HTML characters.

Step 2: Keep only images and commonly used block-level elements

Regular (?i)<(?!/?h|/?p|/?div|br|img).*?> is replaced by empty

Only retain the title tag h segment tag p, div, br and image tag img; the preceding (?i) indicates that it is not case sensitive

Step 3: Remove the selectors or styles of all tags except the img tag, and change the tag to p

Regular <(?!img)(/?)\w+.*?> is replaced by <$1p>

Step 4: Change the messy image styles into standard image codes

Regularly replace <img.*?src="(.+?)".*?> with <img src="$1">

Step 5: Standardize paragraph tags <p>Start</p>End

Regular </?p> replaced with </p><p>

Paragraphs on HC.com only have a <p>start and no</p>end

For some articles on some sites, there is no <p> after the end of </p> and the content of the next paragraph begins directly.

Step 6: Replace the spaces before and after <p> or </p> with empty spaces

Regular \s*(<\/?p>)\s* is replaced by $1

Step 7: Replace more than 2 consecutive <p> or </p> with 1

Regular (<p>){2,}|(</p>){2,} is replaced by $1$2

Step 8: Replace all empty paragraphs with empty paragraphs

Content <p></p> replaced with empty

Step 9: Due to step 5, the beginning of the article may be </p> and the end may be <p> and they need to be cleaned up

Regular ^</p>|<p>$ is replaced by empty

   Filter English regular expressions [a-zA-Z]
   Regular filtering of numbers with more than two digits (\d{2,100})

 

微信赞赏

WeChat

支付宝赞赏

Alipay

✍️ Author: Hong Mu

webmaster · Thanks for reading, stay tuned for more exciting content

Author homepage View home page →

Related articles

Browser caching increases the speed of secondary visits to your website

Browser caching increases the speed of secondary visits to your website Summary of pitfalls

Use browser caching of official words: If users will visit your website multiple times, browser caching of static resources can save users time. Cache headers should be applied to all cacheable static resources, not just to a small subset of static resources (for example, images). Cacheable resources include JS and CSS files, image files, and other binary object files (media files, PDF files, etc.). Normally, HTML doesn’t…
👁 202

Recommended reading

In Traditional Chinese Medicine, when pathogenic factors invade the body – specifically during the Jueyin, Shaoyin, Taiyin, Shaoyang, Yangming, or Taiyang phases – what are the pathways through which these pathogenic factors enter the body, and what are the corresponding clinical manifestations?

In Traditional Chinese Medicine, when pathogenic factors invade the body – specifically during the Jueyin, Shaoyin, Taiyin, Shaoyang, Yangming, or Taiyang phases – what are the pathways through which these pathogenic factors enter the body, and what are the corresponding clinical manifestations? Hobbies Memo notes

According to Traditional Chinese Medicine (TCM) theory, the normal functioning of the human body depends on maintaining the balance of Zheng Qi. Zheng Qi primarily circulates through the six meridians: Jueyin, Shaoyin, Taiyin, Shaoyang, Yangming, and Taiyang. When the body is invaded by pathogenic factors, TCM theory posits that these factors will enter different meridians depending on their nature and direction, thereby giving rise to corresponding clinical manifestations. Below are the pathways through which pathogenic factors invade the various meridians and the corresponding physical symptoms: Jueyin Meridian: When pathogenic factors enter through the sole of the foot, they may cause symptoms such as dry mouth, cough...
👁 185
(Adaptive Mobile Version) Blue English Foreign Trade Website Template – With Three-Level Navigation Menu – 0992

(Adaptive Mobile Version) Blue English Foreign Trade Website Template – With Three-Level Navigation Menu – 0992 Practical Collection pbootcms Template

A blue English-language international trade PbootCMS website template supporting both PC and WAP devices, featuring a three-level navigation structure. The design boasts an international and professional style, making it ideal for various enterprises to build official English-language international trade websites. It helps Chinese manufacturing enterprises showcase their brand image and product competitiveness in the global market. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn – Related...
👁 60
If you want to use Class B within Class A in PHP, how can you do it?

If you want to use Class B within Class A in PHP, how can you do it? Language Notes PHP

If you want to use one class within another PHP class, you can leverage PHP's class instantiation mechanism to create a new class instance and use it. Suppose you have two classes, A and B, and class A needs to use class B; you can instantiate class B within class A. For example: class A { public function doSomething() { $b = new B(); $b->do... }}
👁 151
(Adaptive Mobile Version) High-end Corporate Group Website Template – 0993

(Adaptive Mobile Version) High-end Corporate Group Website Template – 0993 Practical Collection pbootcms Template

A premium, sophisticated PbootCMS website template designed for both PC and WAP devices. Featuring a modern, high-end design and comprehensive functional modules, this template is ideal for large corporate groups to showcase their brand strength and business segments. Template Overview | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn | Related Articles: Complete PbootCMS Security and Maintenance Guide...
👁 42
(Adaptive Mobile Version) Responsive Eco-Friendly Tech Website Template – 0994

(Adaptive Mobile Version) Responsive Eco-Friendly Tech Website Template – 0994 Practical Collection pbootcms Template

A responsive, eco-friendly PbootCMS website template compatible with both PC and WAP devices. Its modern, sustainable design makes it ideal for environmental technology companies to showcase their equipment products, technical solutions, and green initiatives. This template helps environmental enterprises build a strong online brand presence and attract customers. Template Display | Installation Instructions | Website Backend: /admin.php | Username: admin | Password: admin | Extraction Password: www.4s5.cn...
👁 45
Resource website typecho001 template

Resource website typecho001 template Program Notes Typecho

typecho001 template template please do not modify the folder name of this template. The folder name is: typecho001 1.4 Fix the js output problem on the article page 1.3 Fix the error prompt when the plug-in is not installed Optimize the list page code output 1.2 Fix the comment function and add a custom homepage title 1.1 Fix the comment reply asymmetry function Add a separate title setting function on the homepage Add the website favicon.ico icon Add one...
👁 198