2016-11-04 77 views
0

我試圖從這個頁面抓取關注者數量http://freelegalconsultancy.blogspot.co.uk/但似乎無法拉動它。我試過使用urllib,urllib2,urllib3,seleniumbeautiful soup,但沒有運氣拉動追隨者。以下是我的代碼當前的樣子:試圖抓取數據,但不能一刀切(Python)

import urllib2 

url = "http://freelegalconsultancy.blogspot.co.uk/" 

opener = urllib2.urlopen(url) 

for item in opener: 
    print item 

我該如何去拉動追隨者的數量?

+4

一個建議,你可以改變它:使用[要求](HTTP://文檔。 python-requests.org)庫而不是'urllib2'。 –

回答

2

嘗試使用如下代碼selenium

from selenium import webdriver 

driver = webdriver.Firefox() 
driver.get('http://freelegalconsultancy.blogspot.co.uk/') 
driver.switch_to_frame(driver.find_element_by_xpath('//div[@id="followers-iframe-container"]/iframe')) 
followers_text = driver.find_element_by_xpath('//div[@class="member-title"]').text 
followers = int(followers_text.split('(')[1].split(')')[0]) 

最後一行是有點粗魯,所以如果你喜歡