bsObj一直返回“无”

时间:2015-11-25 06:45:19

标签: python selenium beautifulsoup

我正试图抓住这个页面http://www.zillow.com/homes/for_rent/Jackson-County-MO/house,condo,apartment_duplex,mobile,townhouse_type/2295742_zpid/1804_rid/39.299236,-93.017121,38.770145,-95.697785_rect/8_zm/?3col=true

我特意找的描述部分以“首月租金减$ 200”开头

我已经尝试了几种不同的方法,并且因为我的返回值通常得到None - 有时我得到一个Codec错误但是当我尝试使用“class”时这是偶然的:“notranslate”

这是我当前的代码 - 我评论最多,所以输出更容易阅读。

# Import selenium webdriver.
from selenium import webdriver
from bs4 import BeautifulSoup
import time






def getData(url):

    driver = webdriver.Firefox()
    driver.get(url)
    time.sleep(3)
    pageSource = driver.page_source
    bsObj = BeautifulSoup(pageSource)




    # beds 
    #beds = bsObj.find("span", {"class":"addr_bbs"})
    #print(beds)
    # baths 
    #baths = beds.find_next("span", {"class":"addr_bbs"})
    #print(baths)
    # sqft
    #sqft = baths.find_next("span", {"class":"addr_bbs"})
    #print(sqft)
    # rent_amount 
    #rent_amount = bsObj.find("div", {"class":"main-row home-summary-row"}).span
    #print(rent_amount)
    # rent_zestiment
    #rent_zestiment = bsObj.find("div", {"class":"home-summary-row"}).find("span")
    #print(rent_zestiment)
    # days_on_zillow
    #days_on_zillow = bsObj.find("ul", {"class":"zsg-list_square zsg-lg-1-3 zsg-md-1-2 zsg-sm-1-1"})
    #print(days_on_zillow)  
    # subdivision 
    #subdivision = bsObj.find(id="hdp-neighborhood").h2
    #print(subdivision) 
    # property_manager_name 
    #property_manager_name = bsObj.find("span", {"class":"snl company-name"})
    #print(property_manager_name)
    # property_manager_phone
    #property_manager_phone = bsObj.find("span", {"class":"snl phone"})
    #print(property_manager_phone)
    # disc_of_property 
    disc_of_property = bsObj.find(id="yui_3_18_1_1_1448347444636_12522")
    print(disc_of_property)
    # url_of_imgages
    # url_of_listing 

getData(“http://www.zillow.com/homes/for_rent/Jackson-County-MO/house,condo,apartment_duplex,mobile,townhouse_type/2295742_zpid/1804_rid/39.299236,-93.017121,38.770145,-95.697785_rect/8_zm/?3col=true”)

我是一个菜鸟所以任何帮助都会很棒。

1 个答案:

答案 0 :(得分:0)

经过13个小时的演奏后,我终于明白了。

disc_of_property =(bsObj.find('div', {'class': "notranslate"}).text)
print(disc_of_property.encode("utf-8"))

我不得不花费那么多时间来尴尬。