我在Python中使用beautifulsoup时,努力从下面的“结果”中获取链接(即/d/Hinchinbrook+25691+Masjid-Bilal
)。请帮帮忙?
结果:
<div class="subtitleLink"><a href="/d/Hinchinbrook+25691+Masjid-Bilal"><b>Masjid Bilal</b></a></div>
代码:
url1 = "http://www.salatomatic.com/c/Sydney+168"
content1 = urllib2.urlopen(url1).read()
soup = BeautifulSoup(content1)
results = soup.findAll("div", {"class" : "subtitleLink"})
for result in results :
print result
br = result.find('a')
pos = br.get_text()
print pos
答案 0 :(得分:2)
import urllib2
from bs4 import BeautifulSoup
url1 = "http://www.salatomatic.com/c/Sydney+168"
content1 = urllib2.urlopen(url1).read()
soup = BeautifulSoup(content1)
for link in soup.findAll('a'):
print link.get('href')
如果您想要所有链接,这应该有用。如果没有,请告诉我。
答案 1 :(得分:2)