2015-07-05 94 views
1

我試圖寫一個程序,它會打開一個蒸汽社區頁面,然後將讀取的價格表中的第一個值。之後我會做這些事情。我不想使用蒸汽API,如果這是任何人的建議,我想知道如何在表中選擇的第一個ID,因爲它會不斷地變化,我無法定義一組ID,並試圖通過類來定位被證明是困難的。硒蒸汽社區市場上市蟒蛇

我的代碼目前可以打開網頁,是不是從社會市場項目的問題

例。

<div class="market_listing_right_cell market_listing_their_price"> 

<span class="market_table_value"> 
    <span class="market_listing_price market_listing_price_with_fee"></span> 
    <span class="market_listing_price market_listing_price_without_fee"></span> 

回答

2

據我所知,你正在與this page

爲了獲得價格清單,遍歷含有與market_listing_rowdiv元素結果與market_listing_their_price類獲得元素的文本:

for result in driver.find_elements_by_css_selector("div.market_listing_row"): 
    price = result.find_element_by_css_selector("div.market_listing_their_price") 
    print price.text.strip() 

這將打印價格的結果像這樣:

Starting at: $0.63 
Starting at: $0.27 
+0

會爲這個頁面工作http://steamcommunity.com/market/listings/440/Strange%20Pistol –

+0

@DanielPrinsloo是的,定位器看起來一樣,試試看。 – alecxe

+0

你怎麼識別這些作爲CSS選擇器? –