'boa'
如果在列表中,如何保存项目href
列表?我不想使用 get() 打印它们,而是将它们转换为自己变量中的列表(似乎这些在字典中?),最好是boat_links
. 谢谢!
import urllib2
from bs4 import BeautifulSoup
#Open Craigslist with BeautifulSoup and save to file
url = 'http://losangeles.craigslist.org/boo/'
response = urllib2.urlopen(url)
webContent = response.read()
f = open('C:\Users\dell\Desktop\python\\boat_crawler\craigslist.html', 'w')
f.write(webContent)
f.close
html_doc = open('C:\Users\dell\Desktop\python\\boat_crawler\craigslist.html')
soup = BeautifulSoup(html_doc)
boat_links = []
for a in soup.find_all('a'):
if 'boa' in a['href']:
print a.get('href')