How to scrape a string representation of a nested list?

时间:2019-01-20 14:58:43

标签: python web-scraping

I am trying to record the DataCamp courses I have done by using a web scraper. First kudos to this guy, who has built something along my needs,Nextjs Link组件对SEO友好吗?

但是,最近DataCamp对其网站进行了更改,现在综合课程数据不再使用JSON,而是似乎以嵌套列表的字符串表示形式存储。

如果您查看其中一个章节页面的source,则正文中的第一个元素是:

<body><script>window.PRELOADED_STATE = "[&quot;~#iM&quot;,[&quot;preFetchedData&quot;,[&quot;^0&quot;,[&quot;course&quot;,[&quot;^0&quot;,[&quot;status&quot;,&quot;SUCCESS&quot;,&quot;data&quot;,[&quot;^ &quot;,&quot;id&quot;,58,&quot;title&quot;,&quot;Introduction to R ...

因此,原始刮板能够依靠JSON并通过dict键提取信息。有一个想法字段,所以一旦有了基础数据列表,我应该应该能够提取数据。

我尝试通过ast.literal_eval提取字符串表示形式,但这没有用。知道如何使该列表可用吗?

0 个答案:

没有答案
相关问题