2014-02-09 23 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())