0
我是python的新手,我正在嘗試編寫爬蟲程序,我的問題是我無法獲得我想要在控制檯中顯示的href
鏈接。任何幫助表示讚賞,見下文。Python爬蟲的問題
import requests
from bs4 import BeautifulSoup
def trade_spider(max_pages):
page = 1
while page <= max_pages:
url = 'http://www.rent.ie/houses-to-let/renting_dublin/page_'+ str(page)
source_code = requests.get(url)
plain_text = source_code.text
soup = BeautifulSoup(plain_text)
special_divs = soup.findAll('div', {'class':'search_result_title_box'})
for link in special_divs:
gold = link.findAll('a')
for link in gold:
href = gold.get(link['href'])
print(href)
page += 1
trade_spider(3)
非常感謝,完美的作品! – Dom