简体   繁体   English

尝试抓取数据,但无法全部抓取(Python)

[英]Trying to scrape data, but can't scrape it all (Python)

I'm trying to scrape the number of followers from this page http://freelegalconsultancy.blogspot.co.uk/ but can't seem to pull it. 我正在尝试从此页面http://freelegalconsultancy.blogspot.co.uk/抓取追随者,但似乎无法拉开它。 I've tried using urllib , urllib2 , urllib3 , selenium and beautiful soup , but have had no luck pulling the followers. 我试过使用urlliburllib2urllib3seleniumbeautiful soup ,但是没有运气吸引追随者。 Here's what my code looks like currently: 这是我的代码当前的样子:

import urllib2

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

opener = urllib2.urlopen(url)

for item in opener:
    print item

How would I go about pulling the number of followers? 我将如何增加追随者的数量?

Try to use selenium code as below: 尝试使用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])

Last line is kinda rude, so you can change it if you like 最后一行有点粗鲁,因此您可以根据需要进行更改

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM