To install the appropriate library, I am using the PyV8
Note that the function functions written inside need to be surrounded by ()
Copy Code code as follows:
Import PyV8
Class Test ():
Def JS (self):
Ctxt = Pyv8.jscontext ()
Ctxt.enter ()
Func = Ctxt.eval ("" (function () {return ' ### '}) ')
Print func ()
print ' 213 '
if __name__ = = ' __main__ ':
Crawler = Test ()
Crawler.js ()
The result of the output is:
Copy Code code as follows:
Method of passing parameters to JS code
Copy Code code as follows:
Func = Ctxt.eval (function (a) {return encodeURIComponent (a)})
Print Func (a)
A is the parameter that needs to pass, encodeURIComponent is a kind of coding way in JS
I encountered this problem is to do the crawler, the process of post value, some Chinese characters by the site's JS using encodeURIComponent to encode the code can not be submitted, so think of this method in the Python program to encode, and then pass the value, We can solve this problem very well.