[Tutor] Unable to download <th>, <td> using Beautifulsoup
wprins at gmail.com
Fri Jul 29 17:23:54 EDT 2016
On 29 July 2016 at 08:28, Crusier <crusier at gmail.com> wrote:
> I am using Python 3 on Windows 7.
> When I use Google Chrome and use 'View Page Source', the data does not
> show up at all. However, when I use 'Inspect', I can able to read the
> Please kindly explain to me if the data is hide in CSS Style sheet or
> is there any way to retrieve the data listed.
Using inspect is not the same as view source. The inspect tools will give
you the DOM tree as it currently is in the browser. That tree may have been
page source was loaded. It is likely that the data you're trying to get
at, is fetched dynamically after the initial page source is fetched, which
is why you don't see it when using "view source."
engine and reload the webpage. You should then find that you can't see the
data you're after at all, even with inspect, if this is what's occurring.
(To do this for Chrome, see here:
So, if this is what's going on then this presents you with a bit of a
problem. Obviously the Python "requests" module is not a full browser and
same result as a real browser, if the page content is in fact the result of
In order to get around this you would therefore need to fundamentally have
runtime that can effectively process and construct the DOM (and render the
page image if you so desire) before you retrieve the data you're after.
It should be possible to do this, there are projects and questions on the
internet about this. Firstly there's a project named "Selenium" that
provides a way of automating various browsers, and has Python bindings (I
used this some years ago). So you could conceivably use
Python+Selenium+(Chrome or Firefox say) for example to fetch the page and
then get the data out. This has the disadvantage that there's going to be
a real browser and browser window floating around.
A slightly better alternative would be to use a "headless" (displayless)
browser, such as PhantomJS. It is basically the browser engine with lots
of ways to control and automate it. It does not (to my knowledge) include
Python bindings directly, but Selenium includes a PhantomJS driver (I
think.) There's lighter weight options like "jsdom" and "slimerjs", but I
have no idea whether these would suffice or not or whether they would have
Python wrappers or not.
Perhaps the best option might be Ghost.py, which sounds like it might be
exactly what you need, but I have no experience with it.
So, I'm afraid to achieve what you want will require a rather more
complicated solution than what you've currently got. :(
Nevertheless, here's some links for you:
PhantomJS & Python:
I also while answering this question stumbled over the following page
listing (supposedly) almost every headless browser or framework in
I see there's a couple of other possible options on there, but I'll leave
it up to you to investigate.
More information about the Tutor