2014-02-09 44 views
-3

我想识别并从html页面获取javascript。如何使用python从html导出javascript

我该如何使用python做到这一点?

我试过BeautifulSoup但我怎么也找不到......

+0

有没有在你的问题足够的信息。请编辑。你的意思是'从HTML页面获取Javascript' - 你打电话/下载了什么HTML页面?你究竟试过了什么?怎么会失败? –

回答

0
import requests 
import BeautifulSoup as bs 

URL = "page to get" 
pg = requests.get(URL).content 
pg = bs.BeautifulSoup(pg) 

scripts = bs.findAll('script') 

for sc in scripts: 
    try: 
     print("External code at {}".format(sc['src'])) 
    except KeyError: 
     print("Inline code:") 
     print(sc.getText()) 
相关问题