Python Forum
Scraping a dynamic data-table in python through AJAX request
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scraping a dynamic data-table in python through AJAX request
#1
Ref to the stackoverflow thread:
I would like to implement a demo backend script in python in order to scrape the list of document paths through the URL. If I try to handle through the basic request with urllib.request, it does not return the content of the datatable. It is just returned an empty content as below. Hence, the content of the data table might be captured with the AJAX request in this scenario. The example code which is taken from homepage of the actual website (Actual Page). I think main issue here might be token side. How can I handle the python side in order to capture the content of the dynamic datatable?

The code I wrote on python side (Current python code) can not handle this request and returns "The page has expired due to inactivity."

Any suggestions, directions ?

Current python code:

from requests import Session
session = Session()
session.head("mainpage")
response = session.post(
    url= 'apiurl/getviewdatatable',
    data= {
        'name' : 'name',
        'documentPath' : 'documentPath',
    }           
)

print(response.text)
Actual Page: mainpage

<script>
        $(document).ready(function () {
            $('#posts').DataTable({
                "processing": true,
                "serverSide": true,
                "ajax": {
                    "url": "apiurl/getviewdatatable",
                    "dataType": "json",
                    "type": "POST",
                    "data": {
                        _token: "5uC8cmrJRYnn2gB4TCU9EFj0wjgA8BtmqqO64Uk1",
                    }
                },
                "columns": [
                                            {
                        "data": "name"
                    },
                                        {
                        "data": "documentPath"
                    },

                ],
                'createdRow': function (row, data, index) {
                    //
                    // if the second column cell is blank apply special formatting
                    //
                    $(row).addClass('table-row');

                },
                "language": {
                    "url": "//cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/Turkish.json"
                },
                "rowReorder":{
                    selector:'td:nth-child(2)'
                },
            });
        });
</script>
Reply
#2
In python part you also need get token and when you have token use it in request like you use it in javascript part.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to scraping data from dinamic site sergio21124444 2 677 Nov-08-2023, 12:43 PM
Last Post: sergio21124444
  Help Scraping links and table from link cartonics 11 1,537 Oct-12-2023, 06:42 AM
Last Post: cartonics
Question Python request (post/get) Drunknmonkie 1 2,655 Jan-19-2023, 02:02 PM
Last Post: prvncpa
  Retrieve data from ajax pthon3 0 1,181 May-29-2022, 10:32 PM
Last Post: pthon3
  Scraping data from table into existing dataframe vincer58 1 2,003 Jan-09-2022, 05:15 PM
Last Post: vincer58
  Suggestion request for scrapping html table Vkkindia 3 2,021 Dec-06-2021, 06:09 PM
Last Post: Larz60+
  POST Reply to Ajax/jQuery (mostly an HTML question) gw1500se 5 2,667 Nov-18-2021, 02:44 PM
Last Post: gw1500se
  Web scraping data Mike_Eddy 2 2,530 Jul-03-2021, 05:49 PM
Last Post: Mike_Eddy
  Scraping lender data from Ren Ren Dai website using Python. I will pay for that 200$ Hafedh_2021 1 2,752 May-18-2021, 08:41 PM
Last Post: snippsat
  Scraping a page with log in data (security, proxies) iamaghost 0 2,139 Mar-27-2021, 02:56 PM
Last Post: iamaghost

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020