[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务

目录:

  1. 思路
  2. 实现步骤
  3. 注意事项

思路:

1.ARCGIS SERVER MANAGER可以在浏览器中打开并执行各种操作;地址:http://HOST:PORT/arcgis/manager/default.aspx;如图所示。[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第1张图片

2.可以在左侧目录树中点击Services➡Manager Service,在这个页面可以看到MapServer列表,勾选想要操作的服务,可以执行启动,停止,暂停,重启和删除操作。如图所示。

[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第2张图片

3.网页可以操作,那么就可以使用PYTHON爬虫进行操作;

4.爬虫抓包过程从后往前推;

实施步骤

1.模拟启动步骤,抓包信息如下

请求头和响应头:

[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第3张图片COOKIE:

[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第4张图片

请求参数:

[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第5张图片

可以看到,请求头和响应头除了COOKIE之外没有其他变量,COOKIE有两个参数,一个是ASP.NET_SessionId(应该是IIS返回的COOKIE值)一个是ManagerWebCookie(ARCGIS本身返回的COOKIE值);参数中除了查询字符串r、CurrentFolder和__EVENTARGUMENT是变量之外,其余经过验证都是常量(可以更换浏览器或清除缓存后反复尝试对比,也可以直接使用另一个电脑抓包对比)。操作变量是__EVENTARGUMENT: EventArg=buttonClicked&foldername=&sortexpression=Name,ASC&pagenumber=0

所以现在最主要的问题是两个COOKIE是从何而来?

首先按常理猜测两个COOKIE是登录之后服务器返回给浏览器的。下面来验证一下。

2.模拟登录操作

抓包的请求头和响应头如图所示。

[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第6张图片

可以清晰的看到响应头出现了一个COOKIE值ManagerWebCookie,另一个COOKIE值ASP.NET_SessionId竟然出现在请求头里,excuse me?这基本上证明在我们按下登录操作之前,浏览器已经存在ASP.NET_SessionId,下面验证一下想法。

3.登陆界面抓包

抓包前可以先清理浏览器中相关缓存。防止之前的缓存数据造成错觉。如图所示。[ARCGIS]使用PYTHON爬虫控制(启动、停止、暂停、重启和删除)ArcgisServer地图服务_第7张图片

果然是在访问登录界面是响应头中藏着ASP.NET_SessionId值。

4.代码(完全按照浏览器的请求头设置参数)

import requests
import time
url_cookie='http://10.73.9.21/ArcGIS/Manager/login.aspx?ReturnUrl=%2farcgis%2fmanager%2fdefault.aspx'

url_action='http://10.73.9.21/ArcGIS/Manager/Modules/Services/OrganizeServices.aspx?'

def get_NET_SessionId(url):
    headers = {
        'Host': '10.73.9.21',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        'Accept-Encoding': 'gzip, deflate',
        # 'Content-Type': 'application/x-www-form-urlencoded',
        # 'Content-Length': '436',
        'Connection': 'keep-alive',
        'Referer': 'http://10.73.9.21/ArcGIS/Manager/login.aspx?ReturnUrl=%2farcgis%2fmanager%2fdefault.aspx',
        # 'Cookie': 'ASP.NET_SessionId={0}'.format(NET_SessionId),
        'Upgrade-Insecure-Requests': '1',
        # 'Pragma': 'no-cache',
        # 'Cache-Control': 'no-cache',

    }
    r=requests.get(url=url, headers=headers)
    NET_SessionId=r.cookies["ASP.NET_SessionId"]
    return NET_SessionId

def get_ManagerWebCookie(url,NET_SessionId):
    headers = {
        'Host': '10.73.9.21',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',
        'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        'Accept-Encoding': 'gzip, deflate',
        'Content-Type': 'application/x-www-form-urlencoded',
        'Content-Length': '436',
        'Connection': 'keep-alive',
        'Referer': 'http://10.73.9.21/ArcGIS/Manager/login.aspx?ReturnUrl=%2farcgis%2fmanager%2fdefault.aspx',
        'Cookie': 'ASP.NET_SessionId={0}'.format(NET_SessionId),
        'Upgrade-Insecure-Requests': '1',
        'Pragma': 'no-cache',
        'Cache-Control': 'no-cache',
        # 'Cookie':'ASP.NET_SessionId=zc1mkazj1expbzjghs2c1s55',
        # 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',
    }
    formdata = {
        # 'ReturnUrl':'/arcgis/manager/default.aspx',
        '__LASTFOCUS': '',
        '__EVENTTARGET': '',
        '__EVENTARGUMENT': '',
        '__VIEWSTATE': '/wEPDwULLTEyODg3NzUzMDEPZBYCAgMPZBYCAgMPZBYCZg9kFgICAQ9kFgJmD2QWBAITDw8WBB4EVGV4dAUPV0lOLU8yQUhUNUFTT1VTHgdFbmFibGVkaGRkAhUPDxYCHwFoZGRkOfgeE0vlD/41cojdrMaPTlX9V/U=',
        '__EVENTVALIDATION': '/wEWBQLsiLKEBAKUvNa1DwL666vYDAKUko3IDQKnz4ybCLQY3cXN4CDwwoNihCDSoZ+2RxH0',
        'Login1$UserName': 'WIN-O2AHT5ASOUS\\administrator',
        'Login1$Password': 'Cisdi@3327814',
        'Login1$LoginButton': 'Log+In'

    }
    r = requests.post(url=url, headers=headers, data=formdata, allow_redirects=False)
    ManagerWebCookie=r.cookies["ManagerWebCookie"]
    return ManagerWebCookie


def action(NET_SessionId,ManagerWebCookie,actionType,MapServerName):
    headers = {
        'Host': '10.73.9.21',
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0',
        'Accept': '*/*',
        'Accept-Language': 'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2',
        'Accept-Encoding': 'gzip,deflate',
        'X-MicrosoftAjax': 'Delta=true',
        'Cache-Control': 'no-cache',
        'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
        'Content-Length': '7853',
        'Connection': 'keep-alive',
        'Referer': '10.73.9.21/ArcGIS/Manager/Modules/Services/OrganizeServices.aspx?',
        'Cookie': 'ASP.NET_SessionId={0};ManagerWebCookie={1}'.format(NET_SessionId,ManagerWebCookie)
    }
    formdata={
        'ScriptManager1':'ScriptManager1|btnExecuteCommandOnServices',
        'CurrentFolder':'WIN-O2AHT5ASOUS(root)',
        'txtNewFolder':'',
        'ddlProtocols':'Soap',
        'permissionsDialog$domain':'rbLocal',
        'listBox1Values':'',
        'listBox2Values':'',
        '__VIEWSTATE':'/wEPDwUKLTMzNDA2MjU3Ng9kFgICAw9kFh4CAw8PZBYCHgdvbmNsaWNrBewCdmFyIGFyZ3VtZW50PSdFdmVudEFyZz1idXR0b25DbGlja2VkJicgKyAnZm9sZGVybmFtZT0nK1NlcnZpY2VzTWFuYWdlci5DdXJyZW50Rm9sZGVyTmFtZSsnJnNvcnRleHByZXNzaW9uPScrU2VydmljZXNNYW5hZ2VyLlNvcnRFeHByZXNzaW9uKycmcGFnZW51bWJlcj0nK1NlcnZpY2VzTWFuYWdlci5DdXJyZW50UGFnZU51bWJlcjsgdmFyIGNvbnRleHQ9bnVsbDsgX19lc3JpRG9Qb3N0QmFjaygnYnRuU2hvd1NlcnZpY2VzSW5Gb2xkZXInLCdidG5TaG93U2VydmljZXNJbkZvbGRlcicsIGFyZ3VtZW50LCBFU1JJLkFyY0dJUy5NYW5hZ2VyLkZyYW1ld29yay5Db250cm9scy5Qcm9jZXNzTVNBamF4Q2FsbGJhY2tSZXN1bHQsIGNvbnRleHQpO2QCBQ8PZBYCHwAF9gJ2Y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RpwZXJtaXNzaW9uc0RpYWxvZyRyYkRvbWFpbgUjcGVybWlzc2lvbnNEaWFsb2ckbHN0QXZhaWxhYmxlUm9sZXMFIXBlcm1pc3Npb25zRGlhbG9nJGxzdEFsbG93ZWRSb2xlc7+jpQ2OaKvr7vERtCjNG8fSxMaS'.replace('+','+'),
        '__EVENTTARGET':'btnExecuteCommandOnServices',
        '__EVENTARGUMENT':'EventArg=buttonClicked&foldername=&pagenumber=0&operation={0}&names={1}&sortexpression=Name,ASC'.format(actionType,MapServerName),
        '__EVENTVALIDATION':'/wEWGAKuqYyIAgLO28LWDQL9kpmPAQKQ9M/rBQKG3fiUAwL8he6XCQKix7X+BALQi6bcDgL8nKX8CwKS3uy/DgLw3sSlAgKvsprSCQLpuqD2CQKl7tHhBwLvn9vbBQLXxMPxBQLW0M3kAgK844vWCgL2qeeABAK847fIBgLQ5vP6CALZz+ThAQKU/+ZVAsXrrLgLjtGFRcoP0hVFRhFPNj+zMSnC+9A='.replace('+','+'),
        '__ASYNCPOST':'true',
        '':''
    }
    r=requests.post(url=url_action,headers=headers,data=formdata,allow_redirects=False)
    print(r.status_code)
    return r.text

NET_SessionId=get_NET_SessionId(url=url_cookie)
print(NET_SessionId)
ManagerWebCookie=get_ManagerWebCookie(url=url_cookie,NET_SessionId=NET_SessionId)
print(ManagerWebCookie)
time.sleep(5)
re=action(NET_SessionId=NET_SessionId,ManagerWebCookie=ManagerWebCookie,actionType='start',MapServerName=',高家镇_MapServer,三合街道_MapServer')
print(re)



3.注意事项

一个是在获取ManagerWebCookie时,使用POST请求页面会自动重定向,导致拿到的还是NET_SessionId,因此在请求参数中需要设置不能重定向,即allow_redirects=False;

另一个是__VIEWSTATE参数是对Base64进行编码,参数值中包含‘+’号,由于网页传递参数时,会将加号替换成空格,导致报错“Base-64 字符数组的无效长度”。只需要使用str.replace('+','+')将字符串重新替换一下即可。

 

你可能感兴趣的:(PYTHON,ARCGIS)