2017-03-08 26 views
0

我試圖製作一個網站,使用美麗的湯4搜索遊戲的價格(按課)g2a。問題是,當我查看HTML代碼時,它清楚地顯示了第一個結果的價格(£2.30),但是當我在Beautiful Soup 4中搜索課程時,同一班級的標籤之間沒有任何內容:不在BS4上的代碼,但可以在'檢查元素'中找到

http://prnt.sc/ehltnf

http://prnt.sc/ehltwg

#summoningg2a 
r = requests.get('https://www.g2a.com/?search=x') 
data = r.text 
soup = BeautifulSoup(data, 'html.parser') 

#finding prices 
prices = soup.find_all("strong", class_="mp-pi-price-min") 

print(soup.prettify()) 
+0

WRT。屏幕截圖 - 其中一個顯示「mp-pi-price-min」,而另一個顯示「mp-pi-price」,它們是不同的類別。 –

回答

0

在Chrome開發工具中,您可以檢查ajax請求(由Javascript製作)URL。你可以模仿這些請求並獲取數據。

r = requests.get('the ajax requests url') 
data = r.text 

enter image description here

0

requests不處理動態頁面的內容。您最好使用Selenium來驅動瀏覽器。從那裏您可以用BeautifulSoup解析page_source以獲得您要查找的結果。

相關問題