我想從網頁中獲取資料并在其中搜索特定文本。我可以使用 python 來做到這一點,但我想使用 javascript 來做到這一點。我附上了 python 代碼,這樣你就可以理解我想要做什么,以及我如何使用 javascript 來做到這一點。
import requests
a = requests.get("http://localhost:3000/data")
b = a.text
if("wrong" in b):
print(b)
任何幫助將不勝感激。
uj5u.com熱心網友回復:
您可以像這樣在 javascript 中進行正則運算式搜索
fetch('http://google.com')
.then(function (response) {
switch (response.status) {
// status "OK"
case 200:
let text = response.text();
let n = text.search("W3Schools");
console.log(text,n)
// status "Not Found"
case 404:
throw response;
}
})
.then(function (template) {
console.log(template);
})
.catch(function (response) {
// "Not Found"
console.log(response.statusText);
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/451950.html
標籤:javascript 节点.js
上一篇:為什么promise.all會崩潰一個錯誤卻不一個一個地發送promise?
下一篇:谷歌翻譯按鈕根本沒有出現
