0
我需要檢索的是包含/questions/20702626/javac1-8-class-not-found
的href。但輸出我得到下面的代碼是//stackoverflow.com
:從div標籤檢索第一個href
from bs4 import BeautifulSoup
import urllib2
url = "http://stackoverflow.com/search?q=incorrect+operator"
content = urllib2.urlopen(url).read()
soup = BeautifulSoup(content)
for tag in soup.find_all('div'):
if tag.get("class")==['summary']:
for tag in soup.find_all('div'):
if tag.get("class")==['result-link']:
for link in soup.find_all('a'):
print link.get('href')
break;