相关疑难解决方法(0)

使用python从javascript标记中解析可变数据

我正在使用BeautifulSoup和Requests抓取一些网站.我正在检查的页面中有一个数据位于<script language="JavaScript" type="text/javascript">标记内.它看起来像这样:

<script language="JavaScript" type="text/javascript">
var page_data = {
   "default_sku" : "SKU12345",
   "get_together" : {
      "imageLargeURL" : "http://null.null/pictures/large.jpg",
      "URL" : "http://null.null/index.tmpl",
      "name" : "Paints",
      "description" : "Here is a description and it works pretty well",
      "canFavorite" : 1,
      "id" : 1234,
      "type" : 2,
      "category" : "faded",
      "imageThumbnailURL" : "http://null.null/small9.jpg"
       ......
Run Code Online (Sandbox Code Playgroud)

有没有办法可以page_data在此脚本标记中的变量中创建python字典或json对象?那会比使用BeautifulSoup获得价值更好.

html python json beautifulsoup python-requests

12
推荐指数
1
解决办法
1万
查看次数

标签 统计

beautifulsoup ×1

html ×1

json ×1

python ×1

python-requests ×1