从iframe获取价值并将其置于变量中

时间:2017-09-20 08:01:07

标签: javascript jquery html iframe

我正在使用监控过程的PLC控制器开展项目。我现在有一个HTML页面刷新自己并显示寄存器的值。

我正在使用:<iframe src="readreg.htm;reg-R1;fmt-INT;rfs-5"> </iframe>
上面的代码从控制器的内部页面readreg.htm读取寄存器R1的值,我无法看到并输入(它隐藏在某处)。 iframe返回一个值(数字)但当然是帧内。 iframe工作正常。

我想从iframe(寄存器中的数字)中获取值并将其放入变量中,这样我就可以创建一个图表,或者只使用寄存器中的值来做一些数学公式。

我不能使用PHP,只能使用javascript。
我已经尝试了几个星期,但每个解决方案都不起作用。希望你能帮帮我。

1 个答案:

答案 0 :(得分:0)

from __future__ import print_function
import re
import marisa_trie
import os, glob

class wordcut(object):
    def __init__(self, removeRepeat=True, stopDictionary="", removeSpaces=True, minLength=1, stopNumber=False, removeNonCharacter=False, caseSensitive=True, ngram=(1,1), negation=False):
    d = []
    dir = os.path.dirname(__file__)

    # load dictionary
    for file in [f for f in os.listdir(dir + '/dict/') if f.endswith('.txt')]:
        with open(dir + '/dict/' + file) as f:
            for line in f:
                d.append(line.decode('utf-8').rstrip())

    # load negation listdir
    self.negationDict = []
    if negation:
        with open(dir + '/dict/negation.txt') as f:
            for line in f:
                self.negationDict.append(line.decode('utf-8').rstrip())

    self.stopword = False
    self.stopdict = []
    if(stopDictionary is not ""):
        self.stopword = True
        with open(stopDictionary) as f:
            for line in f:
                self.stopdict.append(line.decode('utf-8').rstrip())

    self.trie = marisa_trie.Trie(d)
    self.removeRepeat = removeRepeat
    self.stopNumber = stopNumber
    self.removeSpaces = removeSpaces
    self.minLength = minLength
    self.removeNonCharacter = removeNonCharacter
    self.caseSensitive = caseSensitive
    self.ngram = ngram
    self.negation = negation
    self.onNegation = False

def determine(self, word):
    if self.stopNumber and word.isdigit():
        return False

    if self.removeSpaces and word.isspace():
        return False

    if len(word) < self.minLength:
        return False

    if self.removeNonCharacter:
        match = re.search(u"[0-9A-Za-z\u0E00-\u0E7F]+", word)
        if not match:
            return False

    return True

# Find maximum matching in Trie if match return id else return -1
def searchTrie(self, word):
    # remove negation if see a space
    if(word[0:1] == " "):
        self.onNegation = False

    # check latin words
    match = re.search(u"[A-Za-z\d]*", word)
    if match.group(0):
        if not self.caseSensitive:
            return match.group(0).lower()
        else:
            return match.group(0)

    # check number
    match = re.search(u"[\d]*", word)
    if match.group(0):
        return match.group(0)

    longest = 0
    maxData = None

    for x in range(20):
        if word[0:x] in self.trie:
            longest = len(word[0:x])
            maxData = word[0:x]

    if longest > 20:
        for data in self.trie.keys(word[0:longest]):
            if(len(data) > longest):
                if data in word[0:len(data)]:
                    wordLength = 0
                    longest = len(data)
                    maxData = data


    if maxData:
        try:
            # Special check for case like ๆ
            if word[len(maxData)] == u'ๆ':
                return word[0:(len(maxData) + 1)]
            else:
                return maxData
        except:
            return maxData
    else:
        return -1;

def transform(self, wordArray):
    for dd in self.stopdict:
        try:
            if self.caseSensitive:
                wordArray.remove(dd)
            else:
                wordArray.remove(dd.lower())
        except ValueError:
            pass

    return wordArray

# c = sentence which represent as char
# N = number of character
def find_segment(self, c):
    i = 0
    N = len(c)
    arr = []
    while(i < N):
        j = self.searchTrie(c[i:N])
        if(j == -1):
            if(self.removeRepeat is False or c[i] != c[i - 1]):
                arr.append(c[i])
                i = i + 1
            else:
                i = i + 1
        else:
            k = j
            if self.negation:
                if self.onNegation:
                    k = 'NOT_' + j

                if j in self.negationDict:
                    self.onNegation = True

            arr.append(k)
            i = i + len(j)
    return arr;

def find_ngrams(self, input_list, n):
    return zip(*[input_list[i:] for i in range(n)])

def segment(self, c):
    result = self.find_segment(c)
    if self.stopword:
        result = self.transform(result)

    result = [x for x in result if self.determine(x)]

    lastresult = []
    for x in xrange(self.ngram[0], self.ngram[1]+1):
        for r in self.find_ngrams(result, x):
            match = re.search(u"[A-Za-z\d]+", ''.join(r))
            if not match:
                lastresult.append(''.join(r))
            else:
                if self.negation:
                    lastresult.append(''.join(r))
                else:
                    lastresult.append(' '.join(r))
    return lastresult

ช่วยอธิบายโด๊ดแต่ละบรรทัดให้หน่อย