Skip to content

Instantly share code, notes, and snippets.

@lizhaode
Created December 4, 2019 06:28
Show Gist options
  • Save lizhaode/c841fec33f881843af1938557f85ef9e to your computer and use it in GitHub Desktop.
Save lizhaode/c841fec33f881843af1938557f85ef9e to your computer and use it in GitHub Desktop.
python exec js
from bs4 import BeautifulSoup
import js2py
soup = BeautifulSoup(open('test.html'),'lxml')
div = soup.find(name='div',attrs={'class':'premiumShowTemplate'})
js_content = div.script.string.split('loadScriptUniqueId')[0]
aaa = 'function f(){'+js_content+'if (quality_1080p !== undefined) {return quality_1080p;} else {return quality_720p;}}'
f = js2py.eval_js(aaa)
result = f()
if result is not None:
print(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment