'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')