niexiaosu8167
niexiaosu8167
2017-09-26 22:36

selenium+beautifulsoup 抓取 html table

  • selenium
  • html5

from bs4 import BeautifulSoup
from selenium import webdriver
import urllib2
import time

driver = webdriver.Chrome()
driver.maximize_window()
driver.get("https://www.zillow.com/homes/recently_sold/Culver-City-CA/house,condo,apartment_duplex,townhouse_type/20432063_zpid/51617_rid/12m_days/globalrelevanceex_sort/34.048605,-118.340178,33.963223,-118.47785_rect/12_zm/")
time.sleep(3)
driver.find_element_by_class_name("collapsible-header").click()
soup = BeautifulSoup(driver.page_source)

region = soup.find("div",{"id":"hdp-price-history"})
table = region.find('table',{'class':'zsg-table yui3-toggle-content-minimized'})
print table

需要price/Tax history 的table但是通过class和id定位的结果是None,找不出问题在哪里了

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答