2016-11-11 55 views
0

我想从这个页面凑结果页面的表单:的Python webscraping使用Javascript功能来处理请求

http://data.philly.com/philly/property/

我使用254 W^Ashdale街作为我进入试验,当我这样做在我的浏览器中,它指引我在HTML中寻找的结果(尽管如此)。

Python请求已成功将我放入结果页面的地址放入,但我无法获取所有者信息,这正是我试图抓取的信息。我一直在尝试使用Selenium和Phantomjs,我正在做的没有任何工作。

我也对表单动作感到困惑,它似乎只是与表单所在页面的URL相同。

我感谢任何和所有的建议或帮助!

回答

0

硒几乎处理所有的事情,只需找到元素,输入信息,找到按钮,点击它,然后去找店主,点击它并取消你需要的信息。

import selenium 
from selenium import webdriver 

driver = webdriver.Chrome() 
driver.get('http://data.philly.com/philly/property/') 

#enter the street address 
driver.find_element_by_name('LOC').send_keys('254 W Ashdale St') 
#click on the submit button 
driver.find_element_by_name('sendForm').click() 

#find the owner 
owner_tag = driver.find_elements_by_tag_name('td')[2] 
owner = driver.find_elements_by_tag_name('td')[2].text 
print(owner) 

#click on the owner 
owner_tag.find_element_by_tag_name('a').click() 

#get the table with the relevant info  
rows = driver.find_element_by_tag_name('tbody').find_elements_by_tag_name('tr') 

#get the row with the sale prices 
sale_prices = list() 
for row in rows: 
    sale_prices.append(row.find_elements_by_tag_name('td')[4].text) 

print('\n'.join(sale_prices)) 

输出:

FIRSTNAME LASTNAME 
$123,600.00 
$346,100.00 
[..] 
$789,500.00