2016-11-11 9 views
0

を処理するためにJavascriptを使用してフォームをウェブスクレイピング:Pythonは、私は、このページから結果のページをこすりしようとしています要求

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

私はそれを行うとき、私は、私の裁判のエントリとして254 W Ashdaleセントを使用しています私のブラウザでは、私がHTMLで探している結果に私を誘導します(同じURLですが)。

Pythonの要求が成功し、私は結果ページに入れるのアドレスを入れているが、私はこすりしようとしていているもの、所有者情報を、取得することはできませんよ。私はセレンとファントムを試しています。私がやっていることは何も働いていません。

私は、フォームのアクションについて混乱していた、それだけでフォームがオンになっているページと同じ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 
関連する問題