我想檢測“”部分在哪一行。我用python來處理它。我使用了 re.match(),但它沒有檢測到明顯的行:
import re
filereader = open("template.html", "r")
template = filereader.readlines()
filereader.close()
for d in range(len(template)):
if re.match(r'.*<body onl oad="init(0,0);">.*',template[d]):
wherebody = d
break
print(wherebody)
錯誤在哪里?注意:HTML 檔案有
uj5u.com熱心網友回復:
正如您在此示例中看到的:https ://regex101.com/r/6JcYhk/1 ,您的正則運算式無法與<body onl oad="init(0,0);">. 這是因為(和)被解釋為正則運算式組的開始和結束標記。您可以通過轉義這些字符來解決此問題,這些字符與文字匹配(,)而是:
...
if re.match(r'.*<body onl oad="init\(0,0\);">.*',template[d]):
...
(你可以在前面的例子中嘗試一下,你會看到它開始匹配)
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/416264.html
標籤:
上一篇:WebdriverIO:使用默認運行程式(devtools:puppeteer)找不到Firefox瀏覽器的可執行檔案
