Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从HTML Python中删除Java脚本_Python - Fatal编程技术网

从HTML Python中删除Java脚本

从HTML Python中删除Java脚本,python,Python,我在从HTML中删除Java脚本时遇到问题。我已将HTML的内容放入列表中,希望删除和标记之间的任何文本。请注意,(或)标记在之间可以有任意数量的空格或其他文本。我建议导入,以查找子字符串和之间的文本 但是,如果不想加载包,则需要执行一些变通方法,如本例所示: before_script = html_full.split('<script>')[0] # Getting whatever comes before the script after_script = html_ful

我在从HTML中删除Java脚本时遇到问题。我已将HTML的内容放入列表中,希望删除
标记之间的任何文本。请注意,
(或
)标记在
之间可以有任意数量的空格或其他文本。我建议导入,以查找子字符串
之间的文本

但是,如果不想加载包,则需要执行一些变通方法,如本例所示:

before_script = html_full.split('<script>')[0] # Getting whatever comes before the script
after_script = html_full.split('</script>')[1] # Getting whatever comes after the script
clean_html = before_script + after_script # Adding what comes before with what comes after
before_script=html_full.split(“”)[0]#获取脚本之前的内容
after_script=html_full.split(“”)[1]#获取脚本后面的内容
clean_html=before_script+after_script#添加前面的内容和后面的内容
假设您的HTML文件中只有一个脚本,那么这是可行的。如果有更多,可以从before_脚本和after_脚本列表中删除空值,并将这些值对添加到一起。

能否提供一个?您能否提供一个您试图解析的HTML文件的示例?您不想使用现有模块的原因是什么?因为您试图开发的代码需要花费时间,而使用健壮的现有库会更好。例如,看看
before_script = html_full.split('<script>')[0] # Getting whatever comes before the script
after_script = html_full.split('</script>')[1] # Getting whatever comes after the script
clean_html = before_script + after_script # Adding what comes before with what comes after