试用了Beautifulsoup,的确是个神器。
在抓取到网页时,会出现很多不想要的内容,例如<script>标签,利用beautifulsoup可以很容易去掉。
->
soup = BeautifulSoup('<script>a</script>Hello World!<script>b</script>')
-> [s.extract() for s in soup(‘script’)]
-> soup
Hello World!
如果有多个标签也可以:
-> [s.extract() for s in soup([‘script’, ‘iframe’])]
本文介绍了如何使用BeautifulSoup工具去除HTML中的<script>标签等不需要的部分,以实现更干净的数据抓取效果。
336

被折叠的 条评论
为什么被折叠?



