[英]Python | BS4 How to extract script from <script></script>
簡單的問題,我知道你們中的許多人都比我好得多。 如何從中提取 json 代碼,以便我可以在其上使用 bs4。 在 python 中。 謝謝,請不要降級:)
<script type="text/javascript">window._sharedData = {"config":{"csrf_token":"kkEzPAyLVqXzZaS3xITIlWtkCF6tUi2m","viewer":null,"viewerId":null},"country_code":"PL","language_code":"pl","locale":"pl_PL","entry_data":{"ProfilePage":[{"logging_page_id"..."version":"10"},"is_dev":false,"rollout_hash":"fd856a1a782f","bundle_variant":"es6","frontend_env":"prod"};</script>
我很確定你可以這樣做:
from bs4 import BeautifulSoup
import requests
response = requests.get(URL)
soup = BeautifulSoup(response.text, "lxml")
element = soup.Find("script", type = "text/javascript")
json = element.get("window._sharedData")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.