Skip to main content

Python module to get table data from any webpage and converts it into either Json or Csv

Project description

ScrapeData

Python module to get table data from any webpage and converts it into either Json or Csv

Usage

There are 4 functions exposed which will do all the work for you available in dataConverter

1. convertTableToJsonByClass(URL, tagClass, orientation, tagId = "table")
2. convertTableToJsonByIndex(URL, tagIndex, orientation, tagId = "table")
3. convertTableToCsvByClass(URL, tagClass, fileName, tagId = "table")
4. convertTableToCsvByIndex(URL, tagIndex, fileName, tagId = "table")
  1. URL :- The url from where table needs to fetched
  2. tagClass :- if there is any class associated with tag
  3. tagIndex :- the occurance index of the table you want to fetch.
  4. tagId :- the html tag which is by default table
  5. orientation :-
‘split’ : dict like {‘index’ -> [index], ‘columns’ -> [columns], ‘data’ -> [values]}
‘records’ : list like [{column -> value}, … , {column -> value}]
‘index’ : dict like {index -> {column -> value}}
‘columns’ : dict like {column -> {index -> value}}
‘values’ : just the values array
‘table’ : dict like {‘schema’: {schema}, ‘data’: {data}} describing the data, and the data component is like orient='records'.

There are other functions available in utils if you want to customize the implementation.

1. getDataFromUrl(url)
2. parseDataUsingHtmlParser(page)
3. findTableByClass(soup, tagId, tagClass)
4. findTableByIndex(soup, tagId, tagIndex)
5. convertTableToList(table)
6. convertListToJson(dataList, orientation = 'none')
7. convertListToCsv(dataList, fileName)

Example Code

import dataConverter as dc


URL = 'https://www.w3schools.com/python/module_requests.asp'
tableClass = 'w3-table-all notranslate'

print(dc.convertTableToJsonByClass(URL, tableClass, 'records'))
print(dc.convertTableToJsonByIndex(URL, 0, 'records'))
print(dc.convertTableToCsvByIndex(URL, 0, 'records.csv'))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ScrapeData-0.0.4-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file ScrapeData-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: ScrapeData-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/44.1.1 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/2.7.17

File hashes

Hashes for ScrapeData-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 e4b2b68a78384cc02e6fa5afbae0daddb246fa23f83238c64f6c0d621d4c200b
MD5 919b7eb497d810f281aac9e8c608192c
BLAKE2b-256 8c8d5836a454b4a814551c7d76132b9c2b63d667796b74ce4add8702c5b07f46

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page