This commit is contained in:
白茶清欢 2023-02-11 20:09:03 +08:00
parent 6446cd58f1
commit 428dc77280
2 changed files with 274 additions and 140 deletions

View File

@ -78,7 +78,7 @@ func (c *Chrome) Render(cookieList []*selenium.Cookie) {
//静默执行请求 //静默执行请求
"--headless", // 设置Chrome无头模式在linux下运行需要设置这个参数否则会报错 "--headless", // 设置Chrome无头模式在linux下运行需要设置这个参数否则会报错
"--no-sandbox", "--no-sandbox",
"--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36", // 模拟user-agent防反爬 "--user-agent=Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36", // 模拟user-agent防反爬
}, },
} }
//以上是设置浏览器参数 //以上是设置浏览器参数
@ -94,8 +94,10 @@ func (c *Chrome) Render(cookieList []*selenium.Cookie) {
for _, itemCookie := range cookieList { for _, itemCookie := range cookieList {
err = w_b1.AddCookie(itemCookie) err = w_b1.AddCookie(itemCookie)
if nil != err {
fmt.Println(err) fmt.Println(err)
} }
}
allCookie, _ := w_b1.GetCookies() allCookie, _ := w_b1.GetCookies()
fmt.Println(allCookie) fmt.Println(allCookie)
err = w_b1.Get(url) err = w_b1.Get(url)

View File

@ -31,168 +31,300 @@ type itemCookie struct {
func TestNewChrome(t *testing.T) { func TestNewChrome(t *testing.T) {
cookieJson := `[ cookieJson := `[
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"expirationDate": 1690105309, "hostOnly":false,
"hostOnly": false, "httpOnly":false,
"httpOnly": false, "name":"csg",
"name": "isg", "path":"/",
"path": "/", "sameSite":"no_restriction",
"sameSite": "no_restriction", "secure":true,
"secure": true, "session":true,
"session": false, "storeId":null,
"storeId": null, "value":"fc697e5b"
"value": "BIaGaoCcGV5rRs1MLXd6yKZh13oI58qhGIcoyHCvZamEcyaN2HVhsLYBS6-_W8K5"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"expirationDate": 1690105309, "hostOnly":false,
"hostOnly": false, "httpOnly":false,
"httpOnly": false, "name":"sg",
"name": "tfstk", "path":"/",
"path": "/", "sameSite":"no_restriction",
"sameSite": null, "secure":true,
"secure": false, "session":true,
"session": false, "storeId":null,
"storeId": null, "value":"686"
"value": "cg9FBFXpnTY1tO--kOXy_d93nw_dZzABN5Sct4lddHYKLG5hiAzRjaHP7aqar6f.."
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"hostOnly": false, "hostOnly":false,
"httpOnly": true, "httpOnly":true,
"name": "cookie2", "name":"cookie17",
"path": "/", "path":"/",
"sameSite": "no_restriction", "sameSite":"no_restriction",
"secure": true, "secure":true,
"session": true, "session":true,
"storeId": null, "storeId":null,
"value": "11a2e3f5c45325625d3078fb518e12c2" "value":"UoYenbvzgsH2Rg%3D%3D"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"expirationDate": 1989017049.363698, "expirationDate":1691071546,
"hostOnly": false, "hostOnly":false,
"httpOnly": true, "httpOnly":false,
"name": "enc", "name":"isg",
"path": "/", "path":"/",
"sameSite": "no_restriction", "sameSite":"no_restriction",
"secure": true, "secure":true,
"session": false, "session":false,
"storeId": null, "storeId":null,
"value": "6CoIBy8lnAje2hQ5K99yGofrAdPkNuvRIKCK5JA5Q1%2Boub3YNh5iNsNvpfU4Gc%2F9X98U3fXBxBLv3PYp6%2Fw9Eg%3D%3D" "value":"BCUlEDTRqvr1_M7BGtKJXclsNOdfYtn0p7prhScK4dxrPkWw77LpxLPcyKJIJfGs"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"expirationDate": 2303824744, "expirationDate":1691071546,
"hostOnly": false, "hostOnly":false,
"httpOnly": false, "httpOnly":false,
"name": "cna", "name":"tfstk",
"path": "/", "path":"/",
"sameSite": "no_restriction", "sameSite":null,
"secure": true, "secure":false,
"session": false, "session":false,
"storeId": null, "storeId":null,
"value": "Unx0GIPP62UCAdIMnVT6ZNWT" "value":"cxL1B7jgeKLEdyg0SOGEg-9RLpQAwNrlGV661AqpnM-PVT1cBzW7X890LZ5AO"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"hostOnly": false, "hostOnly":false,
"httpOnly": false, "httpOnly":true,
"name": "_tb_token_", "name":"cookie2",
"path": "/", "path":"/",
"sameSite": "no_restriction", "sameSite":"no_restriction",
"secure": true, "secure":true,
"session": true, "session":true,
"storeId": null, "storeId":null,
"value": "5777de41b7551" "value":"18a65977fe14410e7165b578f17cfcc9"
}, },
{ {
"domain": ".tmall.hk", "domain":"detail.tmall.hk",
"expirationDate": 1690105309, "expirationDate":1678111546,
"hostOnly": false, "hostOnly":true,
"httpOnly": false, "httpOnly":false,
"name": "l", "name":"pnm_cku822",
"path": "/", "path":"/",
"sameSite": null, "sameSite":null,
"secure": false, "secure":false,
"session": false, "session":false,
"storeId": null, "storeId":null,
"value": "fB_jjhQqT3bcamXsBOfwFurza77tQIRAguPzaNbMi9fPO45e5NgCW6R3X-LwCnGVFs9vR38_FFteBeYBcImK10ew8c9WeIkmnmOk-Wf.." "value":"098%23E1hvIQvUvbZvjQCkvvvvvjiWRs5Z1jEjR2dvgj3mPmPZtj1bRsLWgjtPPsdwgjAevpvhvvmv9F9CvvpvvvvvvvhvC9v9vvCvpv9CvhQhRP%2BvClsWafmxdByaWGjxs4hZ%2B3%2Bua4oQD40OwkM6qwVHRfvrcKkxfwkKSeQEfw1lY2Kz8Z0vQbmxdXyaUExr1WkKHkx%2F1W3lYCI7Kvhv8vvvvU1vpvvvvvv2ohCvCVUvvvnUphvp4vvvv63vpCvhvvv2ohCvhvoIvpvUvvmvplsFoXRUvpvjmvmC9cHCtvgCvvpvvvvv"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"expirationDate": 1705193049.363653, "hostOnly":false,
"hostOnly": false, "httpOnly":true,
"httpOnly": false, "name":"cookie1",
"name": "lid", "path":"/",
"path": "/", "sameSite":"no_restriction",
"sameSite": "no_restriction", "secure":true,
"secure": true, "session":true,
"session": false, "storeId":null,
"storeId": null, "value":"BxNXlt0D51JOFzwVkC855E5hMO%2FLJ%2BIjtQKRXjOlrHA%3D"
"value": "baichaqinghuan"
}, },
{ {
"domain": "citizenwatchhk.tmall.hk", "domain":".tmall.hk",
"expirationDate": 1677145308, "hostOnly":false,
"hostOnly": true, "httpOnly":false,
"httpOnly": false, "name":"cancelledSubSites",
"name": "pnm_cku822", "path":"/",
"path": "/", "sameSite":"no_restriction",
"sameSite": null, "secure":true,t
"secure": false, "session":true,
"session": false, "storeId":null,
"storeId": null, "value":"empty"
"value": ""
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"hostOnly": false, "expirationDate":1710079422.393609,
"httpOnly": true, "hostOnly":false,
"name": "sgcookie", "httpOnly":true,
"path": "/", "name":"enc",
"sameSite": "no_restriction", "path":"/",
"secure": true, "sameSite":"no_restriction",
"session": true, "secure":true,
"storeId": null, "session":false,
"value": "E100IilftBf8v72hUSyVYv1LxeVnT75WmX5JvCC%2FiwaVX6Jw%2F0VN5tvc5jeI1pmLlV6PQztlnaJAV7s%2BgN7OZop9YcNrm7SwWEzf%2FVxygdIEDEOMnWyqApcrGHr8YEjkciwn" "storeId":null,
"value":"6CoIBy8lnAje2hQ5K99yGofrAdPkNuvRIKCK5JA5Q1%2Boub3YNh5iNsNvpfU4Gc%2F9X98U3fXBxBLv3PYp6%2Fw9Eg%3D%3D"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"hostOnly": false, "expirationDate":2303824744,
"httpOnly": false, "hostOnly":false,
"name": "t", "httpOnly":false,
"path": "/", "name":"cna",
"sameSite": "no_restriction", "path":"/",
"secure": true, "sameSite":"no_restriction",
"session": true, "secure":true,
"storeId": null, "session":false,
"value": "6f803235fb4e32d8ef21df8238179fbe" "storeId":null,
"value":"Unx0GIPP62UCAdIMnVT6ZNWT"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"hostOnly": false, "hostOnly":false,
"httpOnly": false, "httpOnly":false,
"name": "tracknick", "name":"_l_g_",
"path": "/", "path":"/",
"sameSite": "no_restriction", "sameSite":"no_restriction",
"secure": true, "secure":true,
"session": true, "session":true,
"storeId": null, "storeId":null,
"value": "baichaqinghuan" "value":"Ug%3D%3D"
}, },
{ {
"domain": ".tmall.hk", "domain":".tmall.hk",
"expirationDate": 1674559183, "hostOnly":false,
"hostOnly": false, "httpOnly":false,
"httpOnly": false, "name":"_nk_",
"name": "xlly_s", "path":"/",
"path": "/", "sameSite":"no_restriction",
"sameSite": "no_restriction", "secure":true,
"secure": true, "session":true,
"session": false, "storeId":null,
"storeId": null, "value":"zhangdeman6"
"value": "1" },
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"_tb_token_",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"30407d3b645b3"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"dnk",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"zhangdeman6"
},
{
"domain":".tmall.hk",
"expirationDate":1691071546,
"hostOnly":false,
"httpOnly":false,
"name":"l",
"path":"/",
"sameSite":null,
"secure":false,
"session":false,
"storeId":null,
"value":"fB_jjhQqT3bcatTDBOfaFurza77OSIRYYuPzaNbMi9fP_XfB5rWCW6JFWaY6C3GVF602R38_FFteBeYBc3xonxv9G-QXeLHmndLHR35.."
},
{
"domain":".tmall.hk",
"expirationDate":1707084222.393463,
"hostOnly":false,
"httpOnly":false,
"name":"lid",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":false,
"storeId":null,
"value":"zhangdeman6"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"login",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"true"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":true,
"name":"sgcookie",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"E100RQxy9HrGQ0dqJP7D0skhsmAR0MNIWjOxfE9v%2Booy%2BVv3jquiIls3KiK%2BNCGCVLIO3oLnQg5eHL7p9OxXTQP5zZlMCUWIymMwWp1fGTUu%2F51XqdviOSUH15DdkYu26Isz"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"t",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"6f803235fb4e32d8ef21df8238179fbe"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"tracknick",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"zhangdeman6"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"uc1",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"existShop=false&cookie14=UoezSgPKm%2FLtYA%3D%3D&pas=0&cookie16=U%2BGCWk%2F74Mx5tgzv3dWpnhjPaQ%3D%3D&cookie15=V32FPkk%2Fw0dUvg%3D%3D&cookie21=W5iHLLyFfX5Xzx7qNYvXUg%3D%3D"
},
{
"domain":".tmall.hk",
"hostOnly":false,
"httpOnly":false,
"name":"unb",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":true,
"storeId":null,
"value":"1708690398"
},
{
"domain":".tmall.hk",
"expirationDate":1675605805,
"hostOnly":false,
"httpOnly":false,
"name":"xlly_s",
"path":"/",
"sameSite":"no_restriction",
"secure":true,
"session":false,
"storeId":null,
"value":"1"
} }
]` ]`
var inputCookieList []itemCookie var inputCookieList []itemCookie