【问题标题】:How to export javascript from html using python [closed]如何使用 python 从 html 中导出 javascript [关闭]
【发布时间】:2014-02-09 15:21:42
【问题描述】:

我想从 html 页面中识别并获取 javascript。

我怎样才能使用 python 做到这一点?

我试过BeautifulSoup 但我找不到方法...

【问题讨论】:

  • 您的问题中没有足够的信息。请编辑。你是什​​么意思'从 HTML 页面获取 Javascript' - 什么 HTML 页面,你调用/下载了它吗?你到底试过什么?什么失败了怎么办?

标签: python web-scraping


【解决方案1】:
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())

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多