我在抓这个页面 https://en.wikipedia.org/wiki/Lev_Pavlovich_Rapoport
我已经到了这一点
>>> s2.title.string
u'Lev Pavlovich Rapoport - Wikipedia'
>>> s2.a
<a id="top"></a>
>>> a2=s2.find_all("a")
我会给出几行
[<a id="top"></a>, <a href="#mw-head">navigation</a>, <a href="#p-search">search</a>, <a class="image" href="/wiki/File:LPRapoport1.jpg"><img alt="" class="thumbimage" data-file-height="374" data-file-width="295" height="279" src="//upload.wikimedia.org/wikipedia/commons/thumb/b/bb/LPRapoport1.jpg/220px-LPRapoport1.jpg" srcset="//upload.wikimedia.org/wikipedia/commons/b/bb/LPRapoport1.jpg 1.5x" width="220"/></a>, <a class="internal" href="/wiki/File:LPRapoport1.jpg" title="Enlarge"></a>, <a href="/wiki/Russian_language" title="Russian language">Russian language</a>, <a href="#Early_work"><span class="tocnumber">1</span> <span class="toctext">Early work</span></a>, <a href="#Further_work"><span class="tocnumber">2</span> <span class="toctext">Further work</span></a>, <a href="#Co-workers"><span class="tocnumber">3</span> <span class="toctext">Co-workers</span></a>, <a href="#Recognition"><span class="tocnumber">4</span> <span class="toctext">Recognition</span></a>, <a href="#External_links"><span class="tocnumber">5</span> <span class="toctext">External links</span></a>, <a href=
现在下一步是采取href属性,但是如何?
答案 0 :(得分:3)
如果你像我想象的那样使用BeautifulSoup,你可以这样做。
for a in s2.find_all('a', href=True):
print "Found the URL:", a['href']