python spangt_python怎么爬去spanlt;/span中间标签的内容
展開全部
這個要看你使用32313133353236313431303231363533e4b893e5b19e31333363373765的是什么頁面解析工具了,html?=?"""
item1
item2
"""
#?使用?scrapy?的Selector
from?scrapy.selector?import?Selector
#?scrapy?的選擇器支持?css和xpath選擇。下面是css選擇器。如果你了解前端JQuery的知識,
#?會發(fā)現(xiàn)
Selector(text=html).css('span::text').extract()
#?輸出?:?['item1','item2']
Selector(text=html).css('span#s1::text').extract()
#?輸出?:?['item2']
Selector(text=html).css('div>span::text').extract()
#?輸出?:?['item2']
#?使用bs4
from?bs4?import?BeautifulSoup
soup?=?BeautifulSoup(html,'html.parser')
sl?=?soup.find_all("span")
result?=?[span.get_text()?for?span?in?sl]
print(result)
#?['item1',?'item2']
總結(jié)
以上是生活随笔為你收集整理的python spangt_python怎么爬去spanlt;/span中间标签的内容的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 87狂热
- 下一篇: 基站位置查询系统_木牛导航网络基站服务免