Home
Sign Up
Sign In
推荐学习书目
›
Learn Python the Hard Way
Python Sites
›
PyPI
- Python Package Index
›
http://diveintopython.org/toc/index.html
›
Pocoo
值得关注的项目
›
PyPy
›
Celery
›
Jinja2
›
Read the Docs
›
gevent
›
pyenv
›
virtualenv
›
Stackless Python
›
Beautiful Soup
›
结巴中文分词
›
Green Unicorn
›
Sentry
›
Shovel
›
Pyflakes
›
pytest
Python 编程
›
pep8 Checker
Styles
›
PEP 8
›
Google Python Style Guide
›
Code Style from The Hitchhiker's Guide
V2EX
›
Python
除了BS,还有没有类似于jquery这样的库可以实现这样的功能
kojp
·
Apr 7, 2012
· 4762 views
This topic created in 5334 days ago, the information mentioned may be changed or developed.
<br>
some text
<br>(这个是没封口的)
杯具的是这个标签。用BS不好获取中间的内容。批量替换成<br>some text</br> 又不太现实,因为还牵扯到其它的地方的br标签
br
Text
some
12 replies
•
1970-01-01 08:00:00 +08:00
CoX
Apr 7, 2012
1
<br>本来就是单标签,不是闭合的。
CoX
Apr 7, 2012
2
另外解析页面,我觉得lxml挺不错的
ine181x
Apr 7, 2012
3
br本来就是自闭合的
kojp
OP
Apr 8, 2012
4
@
CoX
谢谢,我试试这个叫lxml的东西吧。
@
ine181x
呃,那基本上就是说用BS来提取br里面的内容是没多希望的喽?(实在是没有其它的正则或者标签能用户了,才想到这个br的)
onedayoneapple
Apr 8, 2012
5
pyquery 用起来和jquery 差不多
kojp
OP
Apr 8, 2012
6
徘徊了好几个库,发现,正则才是王道!
psum=re.compile(r'<br />[\s\S]*<br />')
keakon
Apr 8, 2012
7
@
kojp
不是没希望,而是br本身就没内容…写成xhtml也是这样:
<br/>
some text
<br/>
some text不是br的内容
tamamaxox
Apr 8, 2012
8
bs 是什么
guoquan
Apr 8, 2012
9
请考虑用<span></span>把内容抱起来……
sutar
Apr 8, 2012
10
@
tamamaxox
BeautifulSoup
kojp
OP
Apr 8, 2012
11
@
guoquan
pyquery里面也有wrap_all()?呵呵。。
包起来作何解?把第一个<br>换成<span>,第二个换成</br>
对不?
@
keakon
原来是这样子的呀!我还手动试过变成<br></br>呢。
另外,奇怪的是psum=re.compile(r'<br />[\s\S]*<br />') 这里我本来还想用\把<给转义的。竟然不需要了。转了的话还会出错。
guoquan
Apr 8, 2012
12
@
kojp
写成
<br/>
<span id='foo'>some text</span>
<br/>
About
·
Help
·
Advertise
·
Blog
·
API
·
FAQ
·
Privacy
·
Solana
·
1074 Online
Highest 6679
·
Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 32ms ·
UTC 23:30
·
PVG 07:30
·
LAX 15:30
·
JFK 18:30
♥ Do have faith in what you're doing.
❯