Jump to content

Python parsing help


Midnightsun

Recommended Posts

   https://www.epa.gov/greenpower/green-power-partnership-national-top-100

 

I need to extract table from the website using python pandas and beautiful soup

import pandas as pd
    

.. code:: ipython2

    from bs4 import BeautifulSoup
    import requests

..
code:: ipython2

    url = "https://www.epa.gov/greenpower/green-power-partnership-national-top-100 "

.. code:: ipython2

   
page = requests.get(url)

.. code:: ipython2

    Soup = BeautifulSoup(page.content,'html.parser')


.. code:: ipython2

    table =
Soup.find('div', attrs = {'id':'top'}) 
    
    for row in table.findAll('div',
                             attrs =
{'class':'path-node not-front node-page node-page--node-type-page'}):


::


      File "<ipython-input-23-68516b8d7040>", line 4
 
       attrs = {'class':'path-node not-front node-page node-page--node-type-page'}):
                                       
                                             ^
    IndentationError: expected an indented block
    


.. code:: ipython2

   
filename = 'greenpower.csv'
    with open(filename, 'w') as f:
        w = csv.DictWriter(f)
        w.writeheader()
    
       
  w.writerow(top)
 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...