我在 txt 檔案 (cookie.txt) 中有 cookie 檔案網景格式
像這樣的字串:
*
www.googleadservices.com FALSE /pagead/conversion/978707571/ FALSE 1627665641 Conversion EgwIABUAAAAAHQAAAAAYASD4pcHu056z1PkBSAFqN0VBSWFJUW9iQ2hNSWdyMlhwdi1vOEFJVjBGVmdDaDFXMlFJQkVBQVlBU0FCRWdLc05QRF9Cd0Vwid7vlf-o8AKQAdrswpmZDJgBAA
.google.com TRUE /chrome FALSE 1682961684 _ga GA1.2-2.550592729.1619889685
.chrome.google.com TRUE / FALSE 1682961841 __utma 73091649.1935727784.1619889805.1619889805.1619889805.1
.zenmate.com TRUE / FALSE 1652018810 browser_session
.zenmate.com TRUE / FALSE 1682961844 _ga GA1.2.1460173919.1619889844
widget-mediator.zopim.com FALSE / FALSE 1620494646 AWSALBCORS 7gqxWm82xyFUcYX0r49OUTaI5iBKtuLHeAvuIq2vKYbhlwar D5WIYT0lF6K4q3mdimeTRt/12sP5AD1T4l22iQm2NFDLOrCXhps7oucRNZg 9GlBIUX7/Onz02S
.facebook.com TRUE / FALSE 1683492006 sb YqSVYIj-CWidJrBuYpp3hwWF
.facebook.com TRUE / FALSE 1683491692 datr YqSVYMpaTnIQ053OKhPxted0
.atdmt.com TRUE / FALSE 1683491693 ATN 1.1620419691.12398262919476711770.AYKqLQJgoNbrMvN37Rg
.facebook.com TRUE / FALSE 1654361011 c_user 100007717814705
.google.com TRUE /intl FALSE 1685206659 _ga GA1.2-2.415491287.1622134656
但我只需要以 .facebook.com 開頭的字串
例子:
.facebook.com TRUE / FALSE 1683492006 sb YqSVYIj-CWidJrBuYpp3hwWF
.facebook.com TRUE / FALSE 1683491692 datr YqSVYMpaTnIQ053OKhPxted0
.facebook.com TRUE / FALSE 1654361011 c_user 100007717814705
結束所有其他洗掉。
輸入檔案 cookie.txt -> 僅帶有 .facebook 的輸出字串!
我怎樣才能使它使用 JavaScript ?泰
我嘗試使用 .split 和 .replace ...
uj5u.com熱心網友回復:
嘗試這個..
var string; // your string here...
let lines = string.split("\n"), // get each line
FBstrings = []; // store facebook lines
for (const line of lines) {
if (line && line.startsWith(".facebook.com")) FBstrings.push(line);
}
let stringWithFBOnly = FBstrings.join("\n");
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/524449.html
標籤:javascript细绳
下一篇:熊貓字串洗掉選擇性值組合
