Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7780733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:59:48+00:00 2026-06-01T18:59:48+00:00

I’m doing a research about processing news texts on the internet. So, I’m writing

  • 0

I’m doing a research about processing news texts on the internet. So, I’m writing a program to obtain and store news in a DB by the news url.

For instance, this is a random news url (spanish news website). So, I’m using BeautifulSoup to get the HTML content and after a little bit of simple process I have the news title, summary, content, category and more information about the news.

But, as you can see in the news I used in the example, there is also some “social networking” information (right side of the news image):

  • number of recommendations (facebook)
  • number of tweets (twitter)
  • number of +1s (google+)

I would like to obtain these information too, so I tried to process the HTML content from that part but it’s not there! This is what I’ve done:

>>> import urllib
>>> from BeautifulSoup import BeautifulSoup as Soup
>>> news = urllib.urlopen('http://elcomercio.pe/mundo/1396187/noticia-horror-eeuu-cinco-ninos-muertos-deja-tiroteo-escuela-religiosa')
>>> soup = Soup(news.read())
>>> sociales = soup.findAll('ul', {'class': 'sociales'})[0].findAll('li')
>>> len(sociales)
3

This is the HTML content of the Facebook part:

>>> sociales[0] # facebook
<li class="top">
<div class="fb-plg">
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) {return;}
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=224939367568467";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="http://elcomercio.pe/noticia/1396187/horror-eeuu-cinco-ninos-muertos-deja-tiroteo-escuela-religiosa" data-send="false" data-layout="box_count" data-width="70" data-show-faces="false" data-action="recommend"></div></div></li>

Twitter part:

>>> sociales[1] # twitter
<li><a href="https://twitter.com/share" class="twitter-share-button" data-count="vertical" data-via="elcomercio" data-lang="es">Tweet</a><script type="text/javascript" src="//platform.twitter.com/widgets.js"></script></li>

Google+ part:

>>> sociales[2] # google+
<li><script type="text/javascript" src="https://apis.google.com/js/plusone.js">
  {lang: 'es'}
</script><g:plusone size="tall"></g:plusone></li>

As you can see, the information I’m looking for is not included in the HTML content, I’m guessing it is obtained following those links with a sort of API.

So my question is: is there anyway I can obtain the information I’m looking for (number of facebook recommendations, number of tweets, number of +1s) from the HTML content of a certain news?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:59:50+00:00Added an answer on June 1, 2026 at 6:59 pm

    Here’s my solution. I’m posting it because maybe someday someone will have the same problem. I followed @Hoff advice and I used phantomjs.

    So first I installed it (Linux, Windows or MacOS, doesn’t matter). You just have to be able to run it as a command in your prompt/console like:

    phantomjs file.js
    

    Here is the phantomjs installation guide.

    Then, I made a simple script, that receives an url and returns a BeautifulSoup object (after executing all the javascript):

    import os
    import os.path
    import hashlib
    import subprocess
    from BeautifulSoup import BeautifulSoup
    
    PHANTOM_DIR = os.path.join(os.getcwd(), 'phantom')
    
    try:
        os.stat(PHANTOM_DIR)
    except OSError:
        os.mkdir(PHANTOM_DIR)
    
    PHANTOM_TEMPLATE = """var page = require('webpage').create();  
    page.open('%(url)s', function (status) {
        if (status !== 'success') {
            console.log('Unable to access network');
        } else {
            var p = page.evaluate(function () {
                return document.getElementsByTagName('html')[0].innerHTML
            });
            console.log(p);
        }
        phantom.exit();
    });"""
    
    def get_executed_soup(url):
        """ Returns a BeautifulSoup object with the parsed HTML of the url
            passed, after executing all the scripts in it. """
        file_id = hashlib.md5(url).hexdigest()
        PHANTOM_ABS_PATH = os.path.join(PHANTOM_DIR, 'phantom%s.js' % file_id)
        OUTPUT_ABS_PATH = os.path.join(PHANTOM_DIR, 'output%s.html' % file_id)
        phantom = open(PHANTOM_ABS_PATH, 'w')
        phantom.write(PHANTOM_TEMPLATE % {'url': url})
        phantom.close()
        cmd = 'phantomjs ' + PHANTOM_ABS_PATH + ' > ' + OUTPUT_ABS_PATH
        stdout, stderr = subprocess.Popen(cmd, shell=True).communicate()
        output = open(OUTPUT_ABS_PATH, 'r')
        soup = BeautifulSoup(output.read())
        output.close()
        os.remove(PHANTOM_ABS_PATH)
        os.remove(OUTPUT_ABS_PATH)
        return soup
    

    That’s it!

    PS: I’ve only tested on Linux, so if any of you try this on Windows and/or MacOS, please share your “experience”. Thanks 🙂

    PS 2: I’ve tested in Windows too, works like a charm!

    I also posted this in my personal blog 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I am doing a simple coin flipping experiment for class that involves flipping a
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.