Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions content/pages/about.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Sobre a PythonClub
------------------

:slug: about

Feito pela comunidade para a comunidade, a PythonClub tem como finalidade unir em um único lugar, tudo sobre a linguagem Python e tecnologias relacionadas.

PythonClub é de todos, qualquer pessoa que tenha vontade de colaborar com aquilo que sabe é bem vindo. Assim como Python, *tudo e todos são livres*. Sinta-se a vontade de compartilhar seu conhecimento e experiência, por mais sem importância que seja para você.

A linguagem `Python <http://legacy.python.org/dev/peps/pep-0020/>`_ se destaca no mercado pela facilidade de aprendizado, liberdade de desenvolvimento, e pela sua diversidade, tanto pelos membros da comunidade, quanto em suas aplicações, seja web, desktop, mobile ou científica, então não há restrição de áreas ou assunto.

`Colabore <https://github.com/pythonclub/pythonclub.github.io>`_, e mantenha o projeto ativo.
132 changes: 132 additions & 0 deletions content/parseando-sites-com-beautifulsoup.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
Exemplo de como "Parsear" Sites com BeautifulSoup
#################################################

:date: 2014-05-13 22:00
:tags: beautifulsoup
:category: Python
:slug: parseando-sites-com-beautifulsoup
:author: Gilmar Soares
:email: [email protected]
:github: linuxsoares
:facebook: linux.soares
:twitter: @linux_soares


=================================
Parseando Sites com BeautifulSoup
=================================


Como "pegar" informações de Sites com BeautifulSoup?
----------------------------------------------------

Vamos falar nesse artigo do Beautifulsoup, biblioteca Python necessária para fazer “parse” de sites.

Para iniciarmos o exemplo será necessário instalar a biblioteca Python Beautifulsoup no seu ambiente, e assumo que o leitor tenha PIP instalado, então segue comando para instalação:

.. code-block:: bash

$ pip install beautifulsoup4

A partir desse momento vamos começar a trabalhar com o Beautifulsoup.

Imaginamos que você tenha que fazer parse de um simples site, e que este tenha apenas esse arquivo html:

.. code-block:: bash

$ arquivo_html = ”””<html>
$ <head>
$ <title>
$ Exemplo de Beautifulsoup
$ </title>
$ </head>
$ <body>
$ <p class="title">
$ <b>
$ Exemplo de Beautifulsoup
$ </b>
$ </p>
$ <p class="story">
$ Vamos fazer "parses" desse simples exemplo de html com Beautifulsoup.
$ <a class="sister" href="http://examplo.com/link1" id="link1">
$ Link1
$ </a>
$ ,
$ <a class="sister" href="http://examplo.com/link2" id="link2">
$ Link2
$ </a>
$ and
$ <a class="sister" href="http://examplo.com/link2_teste" id="link2">
$ Link3 Test
$ </a>
$ ; Vamos lá!!!!!!!!!!!!!!!!!!!!!
$ </p>
$ <p class="story">
$ ...
$ </p>
$ </body>
$ </html>”””

Vamos fazer nossa biblioteca ler nossa variavel html, dessa forma:

.. code-block:: bash

$ soup = BeautifulSoup(arquivo_html )

Pronto! Assim como tudo em Python… é simples :)

Agora podemos trabalhar com todo o conteúdo HTML a partir dos métodos da biblioteca.

Para o título:

.. code-block:: bash

$ soup.title: este comando irá trazer o seguinte: => <title>Exemplo de Beautifulsoup</title>

Para as informações desse título:

.. code-block:: bash

$ soup.title.string: este comando irá trazer o seguinte => Exemplo de Beautifulsoup

Para os “P” de HTML:

.. code-block:: bash

$ soup.p: este comando irá trazer o seguinte => <p class="title"><b>Exemplo de Beautifulsoup</b></p>

Para pegar o nome da classe usada no “P”:

.. code-block:: bash

$ soup.p['class']: este comando irá trazer o seguinte => u'title'

Vamos agora demonstrar como fazer uma busca no documento HTML, digamos que tenhamos a necessidade de pegar todos os <a></a> do nosso arquivo HTML, então usaremos o Beautifulsoup da seguinte maneira:

.. code-block:: bash

$ soup.find_all('a'): este comando irá trazer o seguinte =>
$ [
$ <a class="sister"href="http://examplo.com/link1" id="link1">Link1</a>
$ <a class="sister" href="http://examplo.com/link2" id="link2">Link2</a>
$ <a class="sister" href="http://examplo.com/link2_teste" id="link2">Link3 Test</a>
$ ]

Vamos deixar essa busca mais elaborada, vamos buscar um ID especifico do nosso arquivo HTML dessa forma:

.. code-block:: bash

$ soup.find(id="link1"): este comando irá trazer o seguinte =>
$ <a class="sister"href="http://examplo.com/link1" id="link1">Link1</a>

Bom, esta é uma pequena explicação de como funciona o Beautifulsoup. Caso tenham interesse em algo mais especifico, eu utilizei em produção para fazer captura de uns dados, o Script esta no GITHUB no seguinte endereço:
https://github.com/linuxsoares/scripts/blob/master/getVerbos.py
nesse Script implementei bastante coisa do Beautifulsoup e algumas outras coisas também.

Qualquer dúvida pode entrar em contato:
* Email: [email protected]





1 change: 1 addition & 0 deletions pelicanconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# Blogroll
MENUITEMS = (
('Arquivo', 'archives.html'),
('Sobre', 'pages/about.html'),
# ('Autores', 'authors.html'),
# ('Categorias', 'categories.html'),
# ('Tags', 'tags.html'),
Expand Down
46 changes: 38 additions & 8 deletions theme/templates/article.html
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,44 @@ <h1>{{ article.title }}</h1>
<div class="sharing">
<!-- Facebook sharing -->
<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/pt_BR/sdk.js#xfbml=1&appId={{ FACEBOOK_APPID }}&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-share-button" data-href="{{ SITEURL }}/{{ article.url }}" data-type="button_count"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '{{ FACEBOOK_APPID }}', // App ID from the App Dashboard
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// customize share dialog
FB.ui({
method: 'feed',
name: 'PythonClub',
link: 'http://pythonclub.com.br/{{ article.url }}',
picture: 'http://res.cloudinary.com/diu8g9l0s/image/upload/v1399599503/pythonclub/logo_275x130.png',
caption: 'Caption',
description: 'description'

}, function(response) {
if(response && response.post_id){
} else {
}
});
}

// Load the SDK asynchronously
function fb_callout() {(
function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
}
</script>

<div class="fb-share-button" data-href="{{ SITEURL }}/{{ article.url }}" data-type="button_count" onclick="fb_callout()"></div>

<!-- Twitter sharing -->
<a href="https://twitter.com/share" class="twitter-share-button" data-lang="pt">Tweetar</a>
Expand Down