(html, regexs, allow_repeat=True, fetch_one=False, split=None)
| 650 | |
| 651 | # @log_function_time |
| 652 | def get_info(html, regexs, allow_repeat=True, fetch_one=False, split=None): |
| 653 | regexs = isinstance(regexs, str) and [regexs] or regexs |
| 654 | |
| 655 | infos = [] |
| 656 | for regex in regexs: |
| 657 | if regex == "": |
| 658 | continue |
| 659 | |
| 660 | if regex not in _regexs.keys(): |
| 661 | _regexs[regex] = re.compile(regex, re.S) |
| 662 | |
| 663 | if fetch_one: |
| 664 | infos = _regexs[regex].search(html) |
| 665 | if infos: |
| 666 | infos = infos.groups() |
| 667 | else: |
| 668 | continue |
| 669 | else: |
| 670 | infos = _regexs[regex].findall(str(html)) |
| 671 | |
| 672 | if len(infos) > 0: |
| 673 | # print(regex) |
| 674 | break |
| 675 | |
| 676 | if fetch_one: |
| 677 | infos = infos if infos else ("",) |
| 678 | return infos if len(infos) > 1 else infos[0] |
| 679 | else: |
| 680 | infos = allow_repeat and infos or sorted(set(infos), key=infos.index) |
| 681 | infos = split.join(infos) if split else infos |
| 682 | return infos |
| 683 | |
| 684 | |
| 685 | def table_json(table, save_one_blank=True): |
no test coverage detected