python获取script里的内容

Posted Darcy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python获取script里的内容相关的知识,希望对你有一定的参考价值。

import requests
from bs4 import BeautifulSoup

url1 = "https://mip.keoaeic.org/journal_skills/6616.html"
html = requests.get(url1).content
html=html.decode(‘utf-8‘) # python3
soup = BeautifulSoup(html, "html.parser")
a = soup.select(‘script[type="application/ld+json"]‘) 
#查找<script[type="application/ld+json"]> 里面的内容,因为这个地址上面有多个相同的,只需要获取对应的下标内容即可。

t = list(a)[0].text
print(r)

  

以上是关于python获取script里的内容的主要内容,如果未能解决你的问题,请参考以下文章

python里的爬虫如何使用xpath 提取script里的元素?

Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段

怎么提取json里的数据变成EXCEL?

Python怎样获取XPath下的A标签的内容

python如何获取cmd命令框里的内容

怎样用js清除file type里的内容