有什么方法可以打印通过re.search()找到的整个句子吗?

时间:2019-10-18 00:13:57

标签: python regex python-requests

import re
import requests

# a function to clean all HTML tags and attributes (def Clean_HTML(raw_html))
# returns clean_text
site_URL = input("\n Enter a site URL:")
request_site= requests.get(site_URL)
raw_html = request_site.text
text = Clean_HTML(raw_html)

LIST = [""]
x = input("\n enter the number of words to search for:")
for i in range(int(x)):
    LIST.append(input("\n input a word please:")

for item in LIST:
    match = re.search(r"("item")",clean_text)
    print (match)

我需要一种方法来在找到匹配的地方打印整个句子,如果可能的话,将整个段落打印出来。

1 个答案:

答案 0 :(得分:0)

this一样?

with open('text.txt') as f:
  lines = f.readlines()

search = "Nulla"
for line in lines:
  if search in line:
    print(line)