在抓取时,我在提取的数据中获得十六进制代码点,如\u0026#39;和\u003c。问题是在提取时,它们通过在前面得到一个"\“来进行转义,就像\u0026#39和\u003c一样。所以为了解决这个问题,我用了
Tag = response.xpath("//script[contains(.,'" + SplitString + "')]").extract()
Tag = Tag[0].split(SplitString)
Tag = Tag[1].split("\"]")
Tag = codecs.getdecoder('unicode_escape')(Tag[0])[0]
但使用"unicode_escape“的问题是,它改变了一些特殊的符号,如❤️❤️,并将其转换为ŸŽˆ。那么我该如何应对呢?
源代码中的脚本如下所示:
<script nonce="q0OGvOrA73kvqp+Tk1lGIR+glJc">AF_initDataCallback({key: 'ds:4', isError: false , hash: '17', data:function(){return [[["Machineship"]
,null,null,[1]
,null,[["CBSqARUKEwiZjNDE8bDcAhWKI2gKHV8ZDtA\u003d"]
,["CBSqARUKEwiYjNDE8bDcAhWKI2gKHV8ZDtA\u003d"]],[[null,"Enjoy different kind of magazines and entertainment\u003cbr\u003e3 on the various supported classic rule.\u003cbr\u003e\u003cbr\u003e[Feature]\u003cbr\u003e- 1 to max 4 can join\u003cbr\u003e- You can select one of three different patterns.\u003cbr\u003e- :\u003cbr\u003ehttps://www.example.com"]
,[null,"Best \u0026quot;ad-free\u0026quot; entertainment for kids!\u003cbr\u003e❤️❤️"]
]
,null,[[[null,2,[800,1200]............... </script>
我想从中提炼出:给孩子们最好的“无广告”娱乐!
❤️❤️
https://stackoverflow.com/questions/51458016
复制相似问题