提取< Script>的内容在Python中使用BeautifulSoup [英] Extract content of <Script> in Python with BeautifulSoup
本文介绍了提取< Script>的内容在Python中使用BeautifulSoup的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想提取窗口的值. FEED__INITIAL__STATE
我该怎么办?
推荐答案
也许您应该尝试这样:
import requests
from bs4 import BeautifulSoup
def check_script_tag(url):
r = requests.get(url)
parsed_html = BeautifulSoup(r.content, features="html.parser")
try:
text = parsed_html.body.find('script').text
print (text) # Here text in script tag !!
except AttributeError:
print("There is no script tag !!")
check_script_tag("https://stackoverflow.com")
这篇关于提取< Script>的内容在Python中使用BeautifulSoup的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文