Cannot parse table using BeautifulSoup
<p>I have been trying to parse the table <a href="http://podaac.jpl.nasa.gov/ws/search/granule/index.html" rel="nofollow">here</a> with table id = "tblDataset2" and trying to access the rows in the table, but I only get a single row when I parse the webpage using beautifulsoup. 
Here's my code : </p>

<pre><code>from bs4 import BeautifulSoup
import requests

URL = 'http://podaac.jpl.nasa.gov/ws/'
dataset_ids = []
html = requests.get(URL + 'search/granule/index.html')
soup = BeautifulSoup(html.text, 'html.parser')

table = soup.find("table", {"id": "tblDataset2"})
rows = table.find_all('tr')
rows.remove(rows[0])
print table
for row in rows:
    x = row.find_all('td')
    dataset_ids.append(x[0].text.encode('utf-8'))

print dataset_ids
</code></pre>

<p>I want to access all the rows of the table. Please help me with this. Thanks.</p>

<p>This particular dataset is being asynchronously loaded by the browser from a different endpoint which returns a JSON response. Make the request directly to that endpoint:</p>

<pre><code>import requests

URL = 'http://podaac.jpl.nasa.gov/l2ssIngest/datasets'
response = requests.get(URL)
data = response.json()

for item in data["datasets"]:
    print(item["persistentId"], item["shortName"])
</code></pre>

<p>Prints:</p>

<pre><code>(u'PODAAC-AQR40-2SOCS', u'AQUARIUS_L2_SSS_V4')
(u'PODAAC-QSX12-L2B01', u'QSCAT_LEVEL_2B_OWV_COMP_12')
(u'PODAAC-ASOP2-12C01', u'ASCATA-L2-Coastal')
(u'PODAAC-ASOP2-25X01', u'ASCATA-L2-25km')
(u'PODAAC-ASOP2-25B01', u'ASCATB-L2-25km')
(u'PODAAC-ASOP2-COB01', u'ASCATB-L2-Coastal')
(u'PODAAC-J2ODR-GPS00', u'OSTM_L2_OST_OGDR_GPS')
(u'PODAAC-OSCT2-L2BV2', u'OS2_OSCAT_LEVEL_2B_OWV_COMP_12_V2')
(u'PODAAC-RSX12-L2B11', u'RSCAT_LEVEL_2B_OWV_COMP_12_V1.1')
(u'PODAAC-AKASA-XOGD1', u'ALTIKA_SARAL_L2_OST_XOGDR')
(u'PODAAC-GHAM2-2PR72', u'AMSR2-REMSS-L2P-v7.2')
(u'PODAAC-GHVRS-2PN01', u'VIIRS_NPP-NAVO-L2P-v2.0')
(u'PODAAC-RSX12-L2B12', u'RSCAT_LEVEL_2B_OWV_COMP_12_V1.2')
</code></pre>

<p>As for the <em>first dataset</em>, you need to make a GET request to the "search" endpoint:</p>

<pre><code>from operator import itemgetter

import requests


URL = 'http://podaac.jpl.nasa.gov/dmasSolr/solr/dataset/select/'
response = requests.get(URL, params={
    'q': '*:*',
    'fl': 'Dataset-PersistentId,Dataset-ShortName-Full',
    'rows': '2147483647',
    'fq': 'DatasetPolicy-AccessType-Full:(OPEN OR PREVIEW OR SIMULATED OR REMOTE) AND DatasetPolicy-ViewOnline:Y',
    'wt': 'json'
})
data = response.json()

for doc in sorted(data['response']['docs'], key=itemgetter('Dataset-ShortName-Full')):
    print(doc['Dataset-PersistentId'], doc['Dataset-ShortName-Full'])
</code></pre>

<p>Prints:</p>

<pre><code>(u'PODAAC-GHRAM-4FA01', u'ABOM-L4HRfnd-AUS-RAMSSA_09km')
(u'PODAAC-GHGAM-4FA01', u'ABOM-L4LRfnd-GLOB-GAMSSA_28km')
(u'PODAAC-AKASA-XOGD1', u'ALTIKA_SARAL_L2_OST_XOGDR')
(u'PODAAC-USWCO-ALT01', u'ALT_TIDE_GAUGE_L4_OST_SLA_US_WEST_COAST')
...
(u'PODAAC-SASSX-L2WAF', u'WAF_DEALIASED_SASS_L2')
(u'PODAAC-SMMRN-2WAF0', u'WENTZ_NIMBUS-7_SMMR_L2')
(u'PODAAC-SASSX-L2SN0', u'WENTZ_SASS_SIGMA0_L2')
</code></pre>

<hr>

<p>If you prefer not to dive into how the page is loaded and formed, you can use a real browser automated by <a href="http://selenium-python.readthedocs.io/" rel="nofollow"><code>selenium</code></a>.</p>

python html parsing beautifulsoup inspect-element