def getCityIp():
    username = request.query.username
    token = request.query.token
    if not check_login(username, token):
        return genErrorJsonString("login failed")

    province = request.query.province
    city = request.query.city

    region = ''
    if not province == '':
        region = province
    else:
        region = city

    ip = ipProxy.getIpFromRegion(region.encode('utf8'))
    print(ip)
    # 因为Python自带的Json处理中文字符有天生的弱势,所以在此直接返回字符串
    # return { 'region' : region, 'ip' : ip }
    jsonStringToReturn = "{ 'region' : '" + region + "', 'ip' : '" + ip + "'}"
    return jsonStringToReturn 
def getCityIp():
    username = request.query.username
    token = request.query.token
    if not check_login(username, token):
        return genErrorJsonString("login failed")

    province = request.query.province
    city = request.query.city

    region = ''
    if not province == '':
        region = province
    else:
        region = city

    ip = ipProxy.getIpFromRegion(region.encode('utf8'))
    print(ip)
    # 因为Python自带的Json处理中文字符有天生的弱势,所以在此直接返回字符串
    # return { 'region' : region, 'ip' : ip }
    jsonStringToReturn = "{ 'region' : '" + region + "', 'ip' : '" + ip + "'}"
    return jsonStringToReturn
def screenshot():
    print("screenshot start")
    username = request.query.username
    token = request.query.token
    if not check_login(username, token):
        return genErrorJsonString("login failed")

    url = request.query.url
    if url == '':
        return genErrorJsonString("UrlEmptyError!")

    province = request.query.province
    city = request.query.city
    useragent = request.query.useragent
    if useragent == '':
        return genErrorJsonString("UseragentEmptyError")

    region = ''
    if not province == '':
        region = province
    else:
        region = city

    ip = ipProxy.getIpFromRegion(region.encode('utf8'))
    print(url + " " + ip + " " + region + " " + useragent)
    if ip == "IpNotFonud":
        return genErrorJsonString("IpNotFonud")

    try:
        # change the local IP by modify the registration list
        ipProxy.setProxy(ip)

        TIME_FORMAT = '%Y%m%d_%H%M%S'
        currentTime = datetime.datetime.now().strftime(TIME_FORMAT)

        outPutImg = url.replace(".", "").replace("http://www","")\
                 .replace("/","").replace(":","") +\
                 "_" + region + "_" + useragent + "_" + currentTime + ".png"
        # print(outPutImg)
        savedImg = "./snapshot/" + outPutImg
        screenshotScript = "phantomjs screenshot.js " + url + " " \
                + savedImg + " " + useragent;
        print(screenshotScript)

        # subprocess.call(["phantomjs", "screenshot.js", url, savedImg.encode(sys.getfilesystemencoding()), useragent],shell=True)
        # screenResult = os.popen(screenshotScript.encode(sys.getfilesystemencoding()))
        # 解决了中文乱码问题, 使用subprocess可以使得disableProxy可以有效执行
        screenResult = subprocess.call(screenshotScript.encode(\
            sys.getfilesystemencoding()))
        print(screenResult)

        # must diableProxy before return
        if not screenResult == 0:
            return genErrorJsonString("fail to load the address")
    except Exception as e:
        print("ERROR: " + str(e.args))
    finally:
        disableProxyScript = "python ipProxy.py 0"
        os.popen(disableProxyScript)

    outPutImgUrl = LOCAL_IP_ADDRESS + outPutImg
    print(outPutImgUrl)

    jsonStringToReturn = "{ 'screenshotUrl' : '" + outPutImgUrl + "'}"
    return jsonStringToReturn
示例#4
0
import ipProxy

ip = ipProxy.getIpFromRegion("beijing")

print(ip)
print("ip: " + ip)

ipProxy.setProxy(ip)
ipProxy.disableProxy()
ipProxy.refresh()
def screenshot():
    print("screenshot start")
    username = request.query.username
    token = request.query.token
    if not check_login(username, token):
        return genErrorJsonString("login failed")

    url = request.query.url
    if url == '':
        return genErrorJsonString("UrlEmptyError!")

    province = request.query.province
    city = request.query.city
    useragent = request.query.useragent
    if useragent == '':
        return genErrorJsonString("UseragentEmptyError")

    region = ''
    if not province == '':
        region = province
    else:
        region = city

    ip = ipProxy.getIpFromRegion(region.encode('utf8'))
    print(url + " " + ip + " " + region + " " + useragent)
    if ip == "IpNotFonud":
        return genErrorJsonString("IpNotFonud")

    try:
        # change the local IP by modify the registration list
        ipProxy.setProxy(ip)

        TIME_FORMAT = '%Y%m%d_%H%M%S'
        currentTime = datetime.datetime.now().strftime(TIME_FORMAT)

        outPutImg = url.replace(".", "").replace("http://www","")\
                 .replace("/","").replace(":","") +\
                 "_" + region + "_" + useragent + "_" + currentTime + ".png"
        # print(outPutImg)
        savedImg = "./snapshot/" + outPutImg
        screenshotScript = "phantomjs screenshot.js " + url + " " \
                + savedImg + " " + useragent
        print(screenshotScript)

        # subprocess.call(["phantomjs", "screenshot.js", url, savedImg.encode(sys.getfilesystemencoding()), useragent],shell=True)
        # screenResult = os.popen(screenshotScript.encode(sys.getfilesystemencoding()))
        # 解决了中文乱码问题, 使用subprocess可以使得disableProxy可以有效执行
        screenResult = subprocess.call(screenshotScript.encode(\
            sys.getfilesystemencoding()))
        print(screenResult)

        # must diableProxy before return
        if not screenResult == 0:
            return genErrorJsonString("fail to load the address")
    except Exception as e:
        print("ERROR: " + str(e.args))
    finally:
        disableProxyScript = "python ipProxy.py 0"
        os.popen(disableProxyScript)

    outPutImgUrl = LOCAL_IP_ADDRESS + outPutImg
    print(outPutImgUrl)

    jsonStringToReturn = "{ 'screenshotUrl' : '" + outPutImgUrl + "'}"
    return jsonStringToReturn