Python 有没有办法打印使用re.search()找到的整个句子?
我需要一种方法来打印找到匹配的整个句子,如果可能的话,打印整个段落。类似于Python 有没有办法打印使用re.search()找到的整个句子?,python,regex,python-requests,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
因为你只匹配项目单词,所以你可以选择“否”,句子什么时候开始,什么时候结束
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)
with open('text.txt') as f:
lines = f.readlines()
search = "Nulla"
for line in lines:
if search in line:
print(line)