试图刮取数据,但无法刮取所有数据(Python)

2024-10-01 00:27:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从这个页面http://freelegalconsultancy.blogspot.co.uk/中获取关注者的数量,但似乎无法获取。我试过使用urlliburllib2urllib3seleniumbeautiful soup,但没有成功地吸引追随者。下面是我的代码当前的样子:

import urllib2

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

opener = urllib2.urlopen(url)

for item in opener:
    print item

我该怎么做才能吸引更多的追随者呢?你知道吗


Tags: httpurl数量页面openerurllib2urllibitem
1条回答
网友
1楼 · 发布于 2024-10-01 00:27:40

尝试使用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])

最后一行有点粗鲁,所以你可以随意更改

相关问题 更多 >