title: how can I transfer the javascript code to python code?
body: <p>the javascript code is here:    </p>
  
  <pre><code>var goat=6111+7380;
  var hen=5548+7476^goat;
  var seal=2094+4451^hen;
  var rat=1687+7000^seal;
  var pig=3997+8240^rat;
  </code></pre>
  
  <p>And I want get the <code>goat</code>, <code>hen</code> <code>seal</code> variable and so on in the python.
  My python code is here:</p>
  
  <pre><code>animals = 'var goat=6111+7380;var hen=5548+7476^goat;var seal=2094+4451^hen;var rat=1687+7000^seal;var pig=3997+8240^rat;'
  [eval(item.replace('var','').strip()) for item in animals.split(';')]####here is wrong
  </code></pre>
  
  <p>because eval('goat=6111+7380') is wrong, so how can I make the goal is equal the <code>6111+7380</code>?</p>
  
  <p>ps：
  thanks everyone. Actually I craw a website:<code>http://pachong.org/</code> to get the proxy address and the port.But the port is generated by <code>&lt;script&gt;document.write((4513^pig)+15);&lt;/script&gt;</code>.And the <code>pig</code> variable is generated by <code>&lt;script type="text/javascript"&gt;var goat=6111+7380;var hen=5548+7476^goat;var seal=2094+4451^hen;var rat=1687+7000^seal;var pig=3997+8240^rat;&lt;/script&gt;</code>,but this javascript code change every time when I craw the index website.So I do not know how to get the port value.</p>
  
  <pre><code>###resultstring is something like this '(1646^hen)+19'
  def getport(resultstring):
      port = eval(resultstring)
      return port
  
  proxyurl= 'http://www.pachong.org/'
  try:
      r = requests.get(proxyurl,timeout=60*4)
  except:
      print 'I can not get the date of pachong.org'
  if r.status_code != 200:
      print 'the status is not good. status_code is %s' % r.status_code
      return
  ht = BeautifulSoup(r.content)
  animals = str(ht.head.find_all('script')[-1].text)
  [eval(item.replace('var','').strip()) for item in animals.split(';')]###it is wrong here
  
  table = ht.find_all('table', attrs={'class':'tb'})
  if not table:
      return
  table = table[0]
  trs = table.find_all('tr',attrs={'data-type':'high'})
  tr = trs[0]
  idlestring = tr.find_all('td')[5].text
  idlestring = idlestring.replace('\n','').replace(' ','')
  if idlestring == u'空闲':
      # proxy_id += 1
      ip = tr.find_all('td')[1].text
      portstring = tr.find_all('td')[2].text
      patt = re.compile(u'document.write\((.*?)\);')
      if re.findall(patt,portstring):
          resultstring = re.findall(patt,portstring)[0]
      else:
          continue
      port = getport(resultstring)
      ip_port = '%s:%s' % (ip, port)
      print 'ip_port is %s' % ip_port
  </code></pre>