最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【记录】模拟登陆google

Crawl_EmulateLogin crifan 13179浏览 0评论

1.用IE9打开

https://www.google.com.hk/

后,点击右上角的Sign In后,然后输入用户名和密码:

input username and password in google login page

点击Sign in去登陆。

然后就可以看到已经登陆了:

has login google

 

2.很明显,其中的:

https://accounts.google.com/ServiceLoginAuth

就是我们要去登陆时,所访问的地址,其中的post数据是:

continue=https%3A%2F%2Fwww.google.com.hk%2F&dsh=-8258142449249395731&hl=en&GALX=JeKuKwpO1kM&pstMsg=1&dnConn=&checkConnection=youtube%3A449%3A0&checkedDomains=youtube&timeStmp=&secTok=&_utf8=%E2%98%83&bgresponse=%21A0JshyAfjVtBxUQkh0XxQTU7YQIAAAAeUgAAAAYqAObFsjS5wKDdydyQQLZNu1DZ8VbDsE2l0n72Pki8ePly6msM6-zQgAfxxjiVEPBCBjM–g5vMOErerxreRx10V98U_2enOTLD6hJGdVUadehwIUs9NqlFE5Buq5sijWUfYVvjBVqPHjXfv7nsr518MKHIAlTy5OoU71WWcZYPe1h9nZE4teiMPCbQHCSCxFwIkc0v8kHwpg5esRfGuaKH8i5NH28spLdWpXXopgaqm_WDoKbUmPZYJanTUhe8VX8afHZhBpEXT6VmooANFq6EaMYr5_UcLBgJfUH8An67VIESjSGN0HPKQ&[email protected]&Passwd=xxxxxxxxxxxxxxxx&signIn=Sign+in&PersistentCookie=yes&rmShown=1

格式化一下,方便看清楚:

continue=https%3A%2F%2Fwww.google.com.hk%2F
dsh=-8258142449249395731
hl=en
GALX=JeKuKwpO1kM
pstMsg=1
dnConn=
checkConnection=youtube%3A449%3A0
checkedDomains=youtube
timeStmp=
secTok=
_utf8=%E2%98%83
bgresponse=%21A0JshyAfjVtBxUQkh0XxQTU7YQIAAAAeUgAAAAYqAObFsjS5wKDdydyQQLZNu1DZ8VbDsE2l0n72Pki8ePly6msM6-zQgAfxxjiVEPBCBjM--g5vMOErerxreRx10V98U_2enOTLD6hJGdVUadehwIUs9NqlFE5Buq5sijWUfYVvjBVqPHjXfv7nsr518MKHIAlTy5OoU71WWcZYPe1h9nZE4teiMPCbQHCSCxFwIkc0v8kHwpg5esRfGuaKH8i5NH28spLdWpXXopgaqm_WDoKbUmPZYJanTUhe8VX8afHZhBpEXT6VmooANFq6EaMYr5_UcLBgJfUH8An67VIESjSGN0HPKQ
[email protected]
Passwd=xxxxxxxxxxxxxxxx
signIn=Sign+in
PersistentCookie=yes
rmShown=1

对应的,很明显,其中核心参数就是Email和Passwd,以及PersistentCookie=yes,表示记住密码。

 

另外,对应的cookie是:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	GAPS	1:USKpQnqkSYrVAhApy9b84CpdjyzxTQ:7HcRROaII7PCbZhD					
Sent	GoogleAccountsLocale_session	en					
Sent	GALX	JeKuKwpO1kM					
Sent	NID	67=bZtuaZDdaBFpnLQxW4VZAo_urwszZYT6RyTYKkg_cCpwGjoQUE2aI6PQq2Pyb6lKKHaWcKALp3YHYj297X1ZhEP6aDqJUG4gHluQEYDcqGlvMIhh8CwbzZi8_VXwQS51					
Sent	PREF	ID=81d5c3a5968905d8:U=c3ff37527545fdab:LD=en:TM=1349920137:LM=1363070993:S=GmpE2_ZOYRF1qvj7					
Received	GoogleAccountsLocale_session	en	At end of session			Yes	No
Received	GAPS	1:8qyZ0Qd2I6wSy7kEkAT_VfSKKErhFQ:EwkCfkIMGSijc57v	Thu, 12-Mar-2015 09:12:15 GMT		/	Yes	Yes
Received	NID	67=tj6LI4FlShUjkq3_FlJ7fTZYAW4bUItoDwFp_0GjGRlQFswHl2TBG72gHNlAMjf-ja1VIvZUFzFCYCrVi7gcY_X4fNLhqjepRfB5-TkSTBbDc7bsr4vnGCfJG7NauvdU1IHyBQU2UXJYCDMulUKaic-288b_dTnyT1NzR2Wu7y7RgoJ1IZG0JmXsJzc-	Wed, 11-Sep-2013 09:12:15 GMT	.google.com	/	No	Yes
Received	SID	DQAAALwAAAA_a0BLm4YsqKSfOebqXPJnzhVLDKT3iSnPIXu1Ey_MSRPt-yDuz_NlFXdQzfwZFXgbUNuTLaDxbNKafBnS63xKOzsSmVSLgF6FFFySehg9amGSBeZYficyBi1Q_CQBKf5KCnZEkiUQE9glO06Zg39HcY1oAQC5tUIq-h2DtJTxZrXCTBw8DlUZ8ZkwpOAJ8hBMxdsJAz49KLuGA0rplaS8JwfLnXUQQjqfIsUt4E8TWvgFJj-XV0x9iJ6MRNaUbYc	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	No	No
Received	LSID	DQAAAL0AAAC6cFNUd1JYEXyvGUTS5bi06T-CFhmckTxZKV6-mxKSvn_ldu8Y9e37nYes3xFjr2CIzn90B39nrh24_Gtr2dd-T9I-egW72bSq161GwGlOu_tL5Yu6_643Q907xXc9XTo9uZOw3RN_2CbzLQmBVVqaoVkvGqFG_FQb5hgqvmYYYURLLP8u9gBo_O5fLsaUdqZOlWEYeGxXPxrSvj_5buDIN7yvH_jMJhwWGwKJOZoWQdLdow7zJleHqkvMj5RAFPI	Fri, 10-Mar-2023 09:12:15 GMT		/	Yes	Yes
Received	HSID	A163iCeUzycH4Ue8N	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	No	Yes
Received	SSID	AMHGlwpgVv2sY3CkI	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	Yes	Yes
Received	APISID	fuZjiKg_OXx2clqs/ANmmBDFqw4lK4_BQM	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	No	No
Received	SAPISID	qxGncn6r5LqaBBbS/AQ4kCCpKZvvtr5VaU	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	Yes	No

 

所以,接下来,就是先去用代码模拟核心参数,试试是否可以直接登录了。

如果不可以,再去考虑余下的参数,以及相关的cookie了。

3.结果发现,使用简单的代码:

            /*
                continue=https%3A%2F%2Fwww.google.com.hk%2F
                dsh=-8258142449249395731
                hl=en
                GALX=JeKuKwpO1kM
                pstMsg=1
                dnConn=
                checkConnection=youtube%3A449%3A0
                checkedDomains=youtube
                timeStmp=
                secTok=
                _utf8=%E2%98%83
                bgresponse=%21A0JshyAfjVtBxUQkh0XxQTU7YQIAAAAeUgAAAAYqAObFsjS5wKDdydyQQLZNu1DZ8VbDsE2l0n72Pki8ePly6msM6-zQgAfxxjiVEPBCBjM--g5vMOErerxreRx10V98U_2enOTLD6hJGdVUadehwIUs9NqlFE5Buq5sijWUfYVvjBVqPHjXfv7nsr518MKHIAlTy5OoU71WWcZYPe1h9nZE4teiMPCbQHCSCxFwIkc0v8kHwpg5esRfGuaKH8i5NH28spLdWpXXopgaqm_WDoKbUmPZYJanTUhe8VX8afHZhBpEXT6VmooANFq6EaMYr5_UcLBgJfUH8An67VIESjSGN0HPKQ
                [email protected]
                Passwd=xxxxxxxxxxxxxxxx
                signIn=Sign+in
                PersistentCookie=yes
                rmShown=1
             */

            Dictionary<string, string> postDict = new Dictionary<string, string>();
            postDict.Add("hl", "en");
            postDict.Add("Email", txbEmail.Text);
            postDict.Add("Passwd", txbPassword.Text);
            postDict.Add("signIn", "Sign+in");
            postDict.Add("PersistentCookie", "yes");
            string loginGoogleUrl = "https://accounts.google.com/ServiceLoginAuth";
            //songInfo.realAddr = crifanLib.getUrlRespHtml(loginGoogleUrl, headerDict, stHtmlCharset, postDict);    
            string loginRespHtml = crifanLib.getUrlRespHtml(loginGoogleUrl,null, postDict);

是无法正常登陆的。

4.所以还需要另外从头到尾的搞清楚,google 是如何登陆的。

目前看来是:

(1)先访问:

https://www.google.com.hk/

相关的cookie为:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	NID	67=uKGQYf4LRq2bC34tVSeraLXVTszv8qQ8Ten3tp3v51kkZd1c-tdxgPT7H1gY5Ok7ICHj1n9GPvkEOmG15s3etVVeNa3mb-ZbwcZe6koXfDhyXwgMS_xONpZpH0F2RThU					
Sent	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=1:LD=en:NW=1:TM=1349920742:LM=1363078280:SG=1:S=RXWt2Ey6U7sZxcuG					
Received	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=1:LD=en:NW=1:TM=1349920742:LM=1363079516:SG=1:S=kKC4jvadyFHqLEva	Thu, 12-Mar-2015 09:11:56 GMT	.google.com.hk	/	No	No

(2)再访问:

https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.com.hk/

cookie为:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	GAPS	1:nU96JiEPddHvG7Ve2efCsMM0YWYk_w:kIonKP6ZVPh87aVb					
Sent	GoogleAccountsLocale_session	en					
Sent	GALX	JeKuKwpO1kM					
Sent	NID	67=bZtuaZDdaBFpnLQxW4VZAo_urwszZYT6RyTYKkg_cCpwGjoQUE2aI6PQq2Pyb6lKKHaWcKALp3YHYj297X1ZhEP6aDqJUG4gHluQEYDcqGlvMIhh8CwbzZi8_VXwQS51					
Sent	PREF	ID=81d5c3a5968905d8:U=c3ff37527545fdab:LD=en:TM=1349920137:LM=1363070993:S=GmpE2_ZOYRF1qvj7					
Received	GoogleAccountsLocale_session	en	At end of session			Yes	No
Received	GAPS	1:USKpQnqkSYrVAhApy9b84CpdjyzxTQ:7HcRROaII7PCbZhD	Thu, 12-Mar-2015 09:11:59 GMT		/	Yes	Yes

(3)再去:

https://accounts.google.com/ServiceLoginAuth

cookie为:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	GAPS	1:USKpQnqkSYrVAhApy9b84CpdjyzxTQ:7HcRROaII7PCbZhD					
Sent	GoogleAccountsLocale_session	en					
Sent	GALX	JeKuKwpO1kM					
Sent	NID	67=bZtuaZDdaBFpnLQxW4VZAo_urwszZYT6RyTYKkg_cCpwGjoQUE2aI6PQq2Pyb6lKKHaWcKALp3YHYj297X1ZhEP6aDqJUG4gHluQEYDcqGlvMIhh8CwbzZi8_VXwQS51					
Sent	PREF	ID=81d5c3a5968905d8:U=c3ff37527545fdab:LD=en:TM=1349920137:LM=1363070993:S=GmpE2_ZOYRF1qvj7					
Received	GoogleAccountsLocale_session	en	At end of session			Yes	No
Received	GAPS	1:8qyZ0Qd2I6wSy7kEkAT_VfSKKErhFQ:EwkCfkIMGSijc57v	Thu, 12-Mar-2015 09:12:15 GMT		/	Yes	Yes
Received	NID	67=tj6LI4FlShUjkq3_FlJ7fTZYAW4bUItoDwFp_0GjGRlQFswHl2TBG72gHNlAMjf-ja1VIvZUFzFCYCrVi7gcY_X4fNLhqjepRfB5-TkSTBbDc7bsr4vnGCfJG7NauvdU1IHyBQU2UXJYCDMulUKaic-288b_dTnyT1NzR2Wu7y7RgoJ1IZG0JmXsJzc-	Wed, 11-Sep-2013 09:12:15 GMT	.google.com	/	No	Yes
Received	SID	DQAAALwAAAA_a0BLm4YsqKSfOebqXPJnzhVLDKT3iSnPIXu1Ey_MSRPt-yDuz_NlFXdQzfwZFXgbUNuTLaDxbNKafBnS63xKOzsSmVSLgF6FFFySehg9amGSBeZYficyBi1Q_CQBKf5KCnZEkiUQE9glO06Zg39HcY1oAQC5tUIq-h2DtJTxZrXCTBw8DlUZ8ZkwpOAJ8hBMxdsJAz49KLuGA0rplaS8JwfLnXUQQjqfIsUt4E8TWvgFJj-XV0x9iJ6MRNaUbYc	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	No	No
Received	LSID	DQAAAL0AAAC6cFNUd1JYEXyvGUTS5bi06T-CFhmckTxZKV6-mxKSvn_ldu8Y9e37nYes3xFjr2CIzn90B39nrh24_Gtr2dd-T9I-egW72bSq161GwGlOu_tL5Yu6_643Q907xXc9XTo9uZOw3RN_2CbzLQmBVVqaoVkvGqFG_FQb5hgqvmYYYURLLP8u9gBo_O5fLsaUdqZOlWEYeGxXPxrSvj_5buDIN7yvH_jMJhwWGwKJOZoWQdLdow7zJleHqkvMj5RAFPI	Fri, 10-Mar-2023 09:12:15 GMT		/	Yes	Yes
Received	HSID	A163iCeUzycH4Ue8N	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	No	Yes
Received	SSID	AMHGlwpgVv2sY3CkI	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	Yes	Yes
Received	APISID	fuZjiKg_OXx2clqs/ANmmBDFqw4lK4_BQM	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	No	No
Received	SAPISID	qxGncn6r5LqaBBbS/AQ4kCCpKZvvtr5VaU	Fri, 10-Mar-2023 09:12:15 GMT	.google.com	/	Yes	No

 

post数据是上面已经列出来的:

 

 

(4)接着还要去:

https://accounts.google.com/CheckCookie?continue=https%3A%2F%2Fwww.google.com.hk%2F&hl=en&chtml=LoginDoneHtml&checkedDomains=youtube&checkConnection=youtube%3A449%3A0&pstMsg=1

cookie为:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	GAPS	1:USKpQnqkSYrVAhApy9b84CpdjyzxTQ:7HcRROaII7PCbZhD					
Sent	GoogleAccountsLocale_session	en					
Sent	GALX	JeKuKwpO1kM					
Sent	NID	67=bZtuaZDdaBFpnLQxW4VZAo_urwszZYT6RyTYKkg_cCpwGjoQUE2aI6PQq2Pyb6lKKHaWcKALp3YHYj297X1ZhEP6aDqJUG4gHluQEYDcqGlvMIhh8CwbzZi8_VXwQS51					
Sent	PREF	ID=81d5c3a5968905d8:U=c3ff37527545fdab:LD=en:TM=1349920137:LM=1363070993:S=GmpE2_ZOYRF1qvj7					
Sent	GAPS	1:USKpQnqkSYrVAhApy9b84CpdjyzxTQ:7HcRROaII7PCbZhD					
Sent	GoogleAccountsLocale_session	en					
Sent	GALX	JeKuKwpO1kM					
Sent	NID	67=bZtuaZDdaBFpnLQxW4VZAo_urwszZYT6RyTYKkg_cCpwGjoQUE2aI6PQq2Pyb6lKKHaWcKALp3YHYj297X1ZhEP6aDqJUG4gHluQEYDcqGlvMIhh8CwbzZi8_VXwQS51					
Sent	PREF	ID=81d5c3a5968905d8:U=c3ff37527545fdab:LD=en:TM=1349920137:LM=1363070993:S=GmpE2_ZOYRF1qvj7					
Sent	GAPS	1:8qyZ0Qd2I6wSy7kEkAT_VfSKKErhFQ:EwkCfkIMGSijc57v					
Sent	GoogleAccountsLocale_session	en					
Sent	GALX	JeKuKwpO1kM					
Sent	LSID	DQAAAL0AAAC6cFNUd1JYEXyvGUTS5bi06T-CFhmckTxZKV6-mxKSvn_ldu8Y9e37nYes3xFjr2CIzn90B39nrh24_Gtr2dd-T9I-egW72bSq161GwGlOu_tL5Yu6_643Q907xXc9XTo9uZOw3RN_2CbzLQmBVVqaoVkvGqFG_FQb5hgqvmYYYURLLP8u9gBo_O5fLsaUdqZOlWEYeGxXPxrSvj_5buDIN7yvH_jMJhwWGwKJOZoWQdLdow7zJleHqkvMj5RAFPI					
Sent	NID	67=tj6LI4FlShUjkq3_FlJ7fTZYAW4bUItoDwFp_0GjGRlQFswHl2TBG72gHNlAMjf-ja1VIvZUFzFCYCrVi7gcY_X4fNLhqjepRfB5-TkSTBbDc7bsr4vnGCfJG7NauvdU1IHyBQU2UXJYCDMulUKaic-288b_dTnyT1NzR2Wu7y7RgoJ1IZG0JmXsJzc-					
Sent	PREF	ID=81d5c3a5968905d8:U=c3ff37527545fdab:LD=en:TM=1349920137:LM=1363070993:S=GmpE2_ZOYRF1qvj7					
Sent	SID	DQAAALwAAAA_a0BLm4YsqKSfOebqXPJnzhVLDKT3iSnPIXu1Ey_MSRPt-yDuz_NlFXdQzfwZFXgbUNuTLaDxbNKafBnS63xKOzsSmVSLgF6FFFySehg9amGSBeZYficyBi1Q_CQBKf5KCnZEkiUQE9glO06Zg39HcY1oAQC5tUIq-h2DtJTxZrXCTBw8DlUZ8ZkwpOAJ8hBMxdsJAz49KLuGA0rplaS8JwfLnXUQQjqfIsUt4E8TWvgFJj-XV0x9iJ6MRNaUbYc					
Sent	HSID	A163iCeUzycH4Ue8N					
Sent	SSID	AMHGlwpgVv2sY3CkI					
Sent	APISID	fuZjiKg_OXx2clqs/ANmmBDFqw4lK4_BQM					
Sent	SAPISID	qxGncn6r5LqaBBbS/AQ4kCCpKZvvtr5VaU					
Received	GoogleAccountsLocale_session	en	At end of session			Yes	No
Received	GAPS	1:Wr2moK1dys0wGLtQCd1RsetKP-Y_gA:P66TlY_dNgO3mDqm	Thu, 12-Mar-2015 09:12:16 GMT		/	Yes	Yes
Received	SID	DQAAALwAAAA_a0BLm4YsqKSfOebqXPJnXIEQgWEIX7J3ClujKgCbgom2W3XpCtXYXOwSmUXAc0S10uIkaab-UI4Z5efQ-36M7nleQm3LRdkNmkm2IFUD7joKBBh4OBixTYUuvoaU_t149RTmHVuZy3YTHuEkws1qy_BHJcWxnzHADc2QXqFxH5dDVv4TOj1plvTGYpm1WTDeno7aSKUrOpmJM_43r2RBq_5S4Q0HcchAk4IQ30KSnGuER2YAWVfgs6oS9bn6oZ0	Fri, 10-Mar-2023 09:12:16 GMT	.google.com	/	No	No
Received	LSID	s.HK|s.youtube:DQAAAL0AAAC6cFNUd1JYEXyvGUTS5bi0nElYaa537CD6_-PaH2wcsVjyV5_bUmHe-8F4p5hluJ_2F8uw05C342LhqK_u0iKDAz9X47broRRC7pWkGUXYE20cK3yJsfo6H6zVOTU7YjKVoyfJYQyv825ge4C60JYm5s30YsTyFlwzu55NQnI3kdv1_pBY2PwPJcEpoPnhJo3byA9ZTcx-MOmYWpLzWuffKzSZE1lUe4grcQRIiagND3z361_xCVb4Yj9P1_qRsq0	Fri, 10-Mar-2023 09:12:16 GMT		/	Yes	Yes

 

post数据,和上面已经列出来的竟然一样。

 

(5)再去:

https://accounts.google.com.hk/accounts/SetSID?ssdc=1&sidt=ALWU2ctSDVNS44KmriNTK1EqQvprYKCQfcm%2BjxMwFp5%2B%2F%2FrPCslM3VkS5azG9KHl5%2FJmhnmlRDlYkFzxETgyFC47Z2kmtV2rLuGbp%2BOCnwJ80tcZ5PYQ61aEEjp%2Bf8DE1SIJLP4JHSu%2BTpGrIWx2cJcnilh2AKps%2B2MBMEvTBBwx8aKtEuPymew8IamPHhOBmvuLFqvuLmRHRHnXtJWM8y3fkMsKcmHYfsGdwVJUkFviC4xtt5K82F5dK8XsWBr48th3obVIB4oVXnOJaASc%2FUlJsiWY%2B6FCDuGMzqXNxkiBCML3272uQqicElOpBqyd9tiKqnLEwdW32fkkdcfAzFq6SonCq%2BO4EZyMI301py%2BnTfoeUXrqiVAGL2UJg75d7cn0IqlcBRRp&continue=https%3A%2F%2Fwww.google.com.hk%2F

cookie为:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	GAPS	1:SGeom2azC49iiigX9DUio3VJ6B6IJw:eDt62AqIUjUy2zHg					
Sent	GAPS	1:SGeom2azC49iiigX9DUio3VJ6B6IJw:eDt62AqIUjUy2zHg					
Sent	GoogleAccountsLocale_session	en					
Sent	NID	67=uKGQYf4LRq2bC34tVSeraLXVTszv8qQ8Ten3tp3v51kkZd1c-tdxgPT7H1gY5Ok7ICHj1n9GPvkEOmG15s3etVVeNa3mb-ZbwcZe6koXfDhyXwgMS_xONpZpH0F2RThU					
Sent	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=1:LD=en:NW=1:TM=1349920742:LM=1363079516:SG=1:S=kKC4jvadyFHqLEva					
Received	SID	DQAAALsAAAA_a0BLm4YsqKSfOebqXPJnSq69aBpOTfR6dQrMM9Wi_bGGxnp0dhES9sESJo7rhwsJIvQ8TCBxVqTeVLGHK_-liA_odpRism2S3KSKv9lDCHYDxPnY_w_EoTvl5o-NVd3wUEQIMHFR524jE2ebiCOta00-bGlMn96yNBrACGQlljYH3RSRIr4zOFH9x-g03Y9UiIbXk4vC67caLFRzjqRU8v9mK-xI0UMMlhJb5yWhNjrAodyZwArmch0Kdvm6hOQ	Fri, 10-Mar-2023 09:12:17 GMT	.google.com.hk	/	No	No
Received	NID	67=lTjM3YN7Im5m22xnfHQnj-9zFmEeEI0EHKR-mb7WR-VEYKsjRa9NvKPSH7lGOy1e8IcgeDNOgxvl1dzYggaxmrN7FpmiftZGFifApXLH9MAFbhIzhCOmSSQFPWFioaQCWdnBBlbssXN65i9u3X56Vfj5-C8lHfgBr-mBGJHSW32hduyZIVwiCC1j510lHxoZUdoZ45QqNNBMhoM	Wed, 11-Sep-2013 09:12:17 GMT	.google.com.hk	/	No	Yes
Received	HSID	ANfNUPxSAas6psRjW	Fri, 10-Mar-2023 09:12:17 GMT	.google.com.hk	/	No	Yes
Received	SSID	ACvqUOTWrsVCYYV8w	Fri, 10-Mar-2023 09:12:17 GMT	.google.com.hk	/	Yes	Yes
Received	APISID	fuZjiKg_OXx2clqs/ANmmBDFqw4lK4_BQM	Fri, 10-Mar-2023 09:12:17 GMT	.google.com.hk	/	No	No
Received	SAPISID	qxGncn6r5LqaBBbS/AQ4kCCpKZvvtr5VaU	Fri, 10-Mar-2023 09:12:17 GMT	.google.com.hk	/	Yes	No

 

(6)最后才返回来:

https://www.google.com.hk/

对应的cookie是:

Direction	Key	Value	Expires	Domain	Path	Secure	HTTP only
Sent	GoogleAccountsLocale_session	en					
Sent	NID	67=uKGQYf4LRq2bC34tVSeraLXVTszv8qQ8Ten3tp3v51kkZd1c-tdxgPT7H1gY5Ok7ICHj1n9GPvkEOmG15s3etVVeNa3mb-ZbwcZe6koXfDhyXwgMS_xONpZpH0F2RThU					
Sent	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=1:LD=en:NW=1:TM=1349920742:LM=1363079516:SG=1:S=kKC4jvadyFHqLEva					
Sent	GoogleAccountsLocale_session	en					
Sent	NID	67=uKGQYf4LRq2bC34tVSeraLXVTszv8qQ8Ten3tp3v51kkZd1c-tdxgPT7H1gY5Ok7ICHj1n9GPvkEOmG15s3etVVeNa3mb-ZbwcZe6koXfDhyXwgMS_xONpZpH0F2RThU					
Sent	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=1:LD=en:NW=1:TM=1349920742:LM=1363079516:SG=1:S=kKC4jvadyFHqLEva					
Sent	NID	67=lTjM3YN7Im5m22xnfHQnj-9zFmEeEI0EHKR-mb7WR-VEYKsjRa9NvKPSH7lGOy1e8IcgeDNOgxvl1dzYggaxmrN7FpmiftZGFifApXLH9MAFbhIzhCOmSSQFPWFioaQCWdnBBlbssXN65i9u3X56Vfj5-C8lHfgBr-mBGJHSW32hduyZIVwiCC1j510lHxoZUdoZ45QqNNBMhoM					
Sent	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=1:LD=en:NW=1:TM=1349920742:LM=1363079516:SG=1:S=kKC4jvadyFHqLEva					
Sent	SID	DQAAALsAAAA_a0BLm4YsqKSfOebqXPJnSq69aBpOTfR6dQrMM9Wi_bGGxnp0dhES9sESJo7rhwsJIvQ8TCBxVqTeVLGHK_-liA_odpRism2S3KSKv9lDCHYDxPnY_w_EoTvl5o-NVd3wUEQIMHFR524jE2ebiCOta00-bGlMn96yNBrACGQlljYH3RSRIr4zOFH9x-g03Y9UiIbXk4vC67caLFRzjqRU8v9mK-xI0UMMlhJb5yWhNjrAodyZwArmch0Kdvm6hOQ					
Sent	HSID	ANfNUPxSAas6psRjW					
Sent	SSID	ACvqUOTWrsVCYYV8w					
Sent	APISID	fuZjiKg_OXx2clqs/ANmmBDFqw4lK4_BQM					
Sent	SAPISID	qxGncn6r5LqaBBbS/AQ4kCCpKZvvtr5VaU					
Received	PREF	ID=c8e5fc96ddb70edd:U=695e28e9ddfa15ac:FF=2:LR=lang_zh-TW|lang_zh-CN|lang_en:LD=en:NR=10:NW=1:TM=1349920742:LM=1363079537:SG=3:S=c4qflcivk6szzSrt	Thu, 12-Mar-2015 09:12:17 GMT	.google.com.hk	/	No	No
Received	NID	67=C8AdK9hZ6L9FICJdSM7R8ag3cv1FGAfFOCLEpKTmyDK_eOw0yBlopm3Ck-B_6md7Awj_NqKMOfgTSFdf4fwnfKyHYinaMsn88RdoDOVkuPdBO1W_g7vdrvYoqZ6qi0PIZfp5qXuvu--EAm703HAtIDyuOiQvRmC7QF5CZ09rkXFidtyFIwV5DhyaNd-zeixtqb79KP73dCOTFBg	Wed, 11-Sep-2013 09:12:17 GMT	.google.com.hk	/	No	Yes

 

然后才可以看到对应的html,和开始的是类似的:

<!doctype html><html itemscope="itemscope" itemtype="http://schema.org/WebPage"><head><meta http-equiv="X-UA-Compatible"

这样,才算登陆完毕。

3.最后,模拟登陆部分代码如下:

//step1: https://www.google.com/
string googleMainUrl = "https://www.google.com/";
HttpWebResponse mainResp = crifanLib.getUrlResponse(googleMainUrl);
//string mainRespHtml = crifanLib.getUrlRespHtml(googleMainUrl);

//step2: https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.com.hk/
string serviceLoginUrl = "https://accounts.google.com/ServiceLogin?hl=en&continue=https://www.google.com.hk/";
string serviceLoginRespHtml = crifanLib.getUrlRespHtml(serviceLoginUrl);
//HttpWebResponse serviceLoginResp = crifanLib.getUrlResponse(serviceLoginUrl);

//(1)dsh
//  name="dsh" id="dsh" value="1076687533918353426"
//name="dsh" id="dsh" value="-8920038051690744319"
string dshValue = "";
if(crifanLib.extractSingleStr(@"name=""dsh""\s+id=""dsh""\s+value=""([\-\d]+)""", serviceLoginRespHtml, out dshValue))
{

}

//(2)
//<input type="hidden"
//       name="GALX"
//       value="goIJDxmIBok">
string galxValue = "";
if (crifanLib.extractSingleStr(@"name=""GALX""\s+value=""(\w+)""", serviceLoginRespHtml, out galxValue))
{

}

//step3: https://accounts.google.com/ServiceLoginAuth
/*
    continue=https%3A%2F%2Fwww.google.com.hk%2F
    dsh=-8258142449249395731
    hl=en
    GALX=JeKuKwpO1kM
    pstMsg=1
    dnConn=
    checkConnection=youtube%3A449%3A0
    checkedDomains=youtube
    timeStmp=
    secTok=
    _utf8=%E2%98%83
    bgresponse=%21A0JshyAfjVtBxUQkh0XxQTU7YQIAAAAeUgAAAAYqAObFsjS5wKDdydyQQLZNu1DZ8VbDsE2l0n72Pki8ePly6msM6-zQgAfxxjiVEPBCBjM--g5vMOErerxreRx10V98U_2enOTLD6hJGdVUadehwIUs9NqlFE5Buq5sijWUfYVvjBVqPHjXfv7nsr518MKHIAlTy5OoU71WWcZYPe1h9nZE4teiMPCbQHCSCxFwIkc0v8kHwpg5esRfGuaKH8i5NH28spLdWpXXopgaqm_WDoKbUmPZYJanTUhe8VX8afHZhBpEXT6VmooANFq6EaMYr5_UcLBgJfUH8An67VIESjSGN0HPKQ
    [email protected]
    Passwd=xxxxxxxxxxxxxxxx
    signIn=Sign+in
    PersistentCookie=yes
    rmShown=1
 */
Dictionary<string, string> headerDict = new Dictionary<string, string>();
headerDict.Add("Referer", serviceLoginUrl);
headerDict.Add("AllowAutoRedirect", "false"); //disable auto direct to "collect" intermediate cookies, for latter use
Dictionary<string, string> postDict = new Dictionary<string, string>();
postDict.Add("continue", "https://www.google.com.hk/");
postDict.Add("dsh", dshValue);
postDict.Add("hl", "en");
postDict.Add("GALX", galxValue);

postDict.Add("Email", txbEmail.Text);
postDict.Add("Passwd", txbPassword.Text);
postDict.Add("signIn", "Sign+in");
postDict.Add("PersistentCookie", "yes");
string loginGoogleUrl = "https://accounts.google.com/ServiceLoginAuth";
//songInfo.realAddr = crifanLib.getUrlRespHtml(loginGoogleUrl, headerDict, stHtmlCharset, postDict);    
//string loginRespHtml = crifanLib.getUrlRespHtml(loginGoogleUrl, headerDict, postDict);
HttpWebResponse loginResp = crifanLib.getUrlResponse(loginGoogleUrl, headerDict, postDict);

//step 4:
//https://accounts.google.com/CheckCookie?continue=http%3A%2F%2Fwww.google.com.hk%2F&hl=en&chtml=LoginDoneHtml&checkedDomains=youtube&pstMsg=1
string checkCookieUrl = loginResp.Headers["Location"].ToString();
headerDict = new Dictionary<string, string>();
headerDict.Add("Referer", serviceLoginUrl);
headerDict.Add("AllowAutoRedirect", "false"); //disable auto direct to get follow SetSID url           
HttpWebResponse checkCookieResp = crifanLib.getUrlResponse(checkCookieUrl, headerDict);

//step5:
string setSidUrl = checkCookieResp.Headers["Location"].ToString();
//https://accounts.google.com.hk/accounts/SetSID?ssdc=1&sidt=ALWU2cvJkixPgxsSKW%2FcQGNuwdI6xSYJ6vDOlR%2FIQTZ%2BYFdgoHfCMHhwtirBMvOdf1%2FheS3W40l8zXqDbNva9ncceD%2BWMYOMmlJulirhNmdXC9DzTO5VSAaiwJfIeE9yvVeWHcjtCi5bPKlhufDt6R0ZDwmVYnYW39ysHwAw0b7cMlx5lCI3guMWukWhnPwgnCO7eDfJ6wvdgGnaPYtdRCrzL%2FY8chelqeyzp%2BKsMv97hrF7mmzwnf9BgdIF29MMJHYWCvBfI6VPZ0iRjR4KqwZrqkug9BRsE0lcGkgI2Qi1OjB0aS3wJIj1d4J589t6BVWqnT%2BsN1fu3VYS%2B6U6l5J6j0vFqkT%2BBwLcvYmjf%2FwnoU19GnT09bWOAS8RsotBnV6sYoysna85&continue=http%3A%2F%2Fwww.google.com.hk%2F
headerDict = new Dictionary<string, string>();
headerDict.Add("Referer", serviceLoginUrl);
headerDict.Add("AllowAutoRedirect", "false"); //disable auto direct to get follow SetSID url
string setSidHtml = crifanLib.getUrlRespHtml(setSidUrl, headerDict);
//location.replace("http://www.google.com.hk/")
string redirectUrl = "";
if (crifanLib.extractSingleStr(@"location\.replace\(""(http.+?)""\)", setSidHtml, out redirectUrl))
{

}
//The document has moved <A HREF="https://www.google.com.hk/">here</A>
else if (crifanLib.extractSingleStr(@"A\s+HREF=""(http.+?)""", setSidHtml, out redirectUrl))
{ 

}

//step6:
//redirecting to :
//http://www.google.com.hk/
string realMainHtml = crifanLib.getUrlRespHtml(redirectUrl);
//search resp html, check whether contain the user email
//to see wheter login ok
Match found = new Regex(txbEmail.Text).Match(realMainHtml);
if (found.Success)
{
    MessageBox.Show("Login OK");
}
else
{
    MessageBox.Show("Login failed!");
}

注:

1. 相关的crifanLib的库,详见:

crifanLib – crifan’s Library(C#/Python/PHP/C/…)

2.此过程,正常的情况下,是正常的,可以模拟登陆的。

在调试期间,偶尔,好像是google服务器端异常,还是C#的http库异常,会导致:

string setSidUrl = checkCookieResp.Headers["Location"].ToString();

中response中的Headers中,没有Location,所以会报错。

其根本原因,暂未知。只是发现偶尔会出现此问题。

转载请注明:在路上 » 【记录】模拟登陆google

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

网友最新评论 (8)

  1. 你好,最近正在模拟登陆google trend,你的文章给我很大的启发。 可是我走到第4步验证cookies的时候,访问"https://accounts.google.com/CheckCookie?chtml=LoginDoneHtml&continue=https://www.google.com/trends/&gidl=CAA", 总是报400错误。这是为什么呢?
    linda10年前 (2015-07-17)回复
    • 不好意思,没精力去帮你调试,所以不太清楚。搜了下,400是Bad Request,所以应该是:你模拟登陆的逻辑没有模拟对。所以需要先去用工具分析对应的逻辑,然后再去模拟才可以。
      crifan10年前 (2015-07-20)回复
  2. 我也在研究,不过貌似你把最关键的没写清楚,就是 bgresponse 这个参数的值,是怎么得来的。其他都很简单。
    yuhe12年前 (2013-06-26)回复
  3. 有点复杂
    补习生12年前 (2013-03-12)回复
93 queries in 0.215 seconds, using 22.28MB memory