(page_html, pattern_str, pattern_ignore_case=re.I)
| 36 | |
| 37 | # 从页面中提取需要的部分(通常是链接也可以通过正则表达式进行指定) |
| 38 | def get_matched_parts(page_html, pattern_str, pattern_ignore_case=re.I): |
| 39 | pattern_regex = re.compile(pattern_str, pattern_ignore_case) |
| 40 | return pattern_regex.findall(page_html) if page_html else [] |
| 41 | |
| 42 | |
| 43 | # 开始执行爬虫程序并对指定的数据进行持久化操作 |