这个问题有点蹩脚:我在这个网站页面上使用美味汤,url =' http://www.rentatbelleparkeast.com/Apartments/module/property_info/property%5Bid%5D/13578/' ,提取以下信息。 1.姓名 2.地址 3.电话 4.公寓价格(租金,布局 - 床/浴室/大小。 我有以下简单的代码,但我没有正确的锚标记来提取实际信息。我在搜索结果中变得空白(无)。
import urllib
from BeautifulSoup import *
url = 'http://www.rentatbelleparkeast.com/Apartments/module/property_info/property%5Bid%5D/13578/'
html = urllib.urlopen(url).read()
#Create beautiful soup object
soup = BeautifulSoup(html)
print soup
# Retrieve a list of the anchor tags
# Each tag is like a dictionary of HTML attributes
#For Phone I use tag 'span'
tag = soup('span')
#I search for Phone tag but this gives blank output
phone = soup.find(text= 'Phone: ')
# I use tag 'td' to get all information from the tables
tab = soup.findAll('td')
print tab # This gives the object with all information I need
#I extract, for example, Rent using the following loop. I get blank (None) results
for i in tab:
print i.get('Rent *', None)
答案 0 :(得分:0)
简单的名称,地址和手机你可以使用
name = ' '.join(soup.find('div', {'class': 'limitedTitle'}).text.split())
adress = ' '.join(soup.find('div', {'class': 'limitedText'}).text.split())
phone = ''.join(soup.find('div', {'class': 'propertyContactText'}).text.split())