【发布时间】:2015-05-29 02:02:34
【问题描述】:
我需要检索的是包含/questions/20702626/javac1-8-class-not-found 的href。但是我得到的下面代码的输出是//stackoverflow.com:
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;
【问题讨论】:
标签: python html beautifulsoup html-parsing href