0

from the title it may look a duplicate of other questions, but would request to read the question and if it is duplicate please point me to that thread. I am trying to read the data from a URL:

Here is the code

import requests
url = 'https://www.eticketing.co.uk/tottenhamhotspur/interfaces/availability_isc.ashx?eventref=8570'
local_filename = 'abc.xml'

with requests.get(url, stream=True) as r:
    with open(local_filename, 'wb') as f:
        for data in r.iter_content(chunk_size=512):
            f.write(data)

Another way for doing above

local_filename = 'abc1.xml'
r = requests.get(url)

with open(local_filename, 'wb') as f:
    f.write(r.content);

Neither abc.xml not abc1.xml have same data as on url, on that url there are 51608, but lines that get copied are sometimes 50140, sometimes 51124 and so on.

I am not sure if I am doing something wrong, but I want to copy all the data from that URL into a local file.

Georgy
  • 12,464
  • 7
  • 65
  • 73
deepakl
  • 172
  • 8
  • Since the response data is in XML format, I suggest using xml.Etree.ElementTree to convert the fetched data in the appropriate format and then write it to a file. The answers in this thread might be useful : [https://stackoverflow.com/questions/29810572/save-xml-response-from-get-call-using-python](Link) – Anshuman Tiwari Sep 18 '19 at 11:56
  • Thanks @AnshumanTiwari for pointer, but they are not working as well i.e. complete data is not getting copied. – deepakl Sep 18 '19 at 12:14

1 Answers1

0

It seems that file is dynamically generated each time you requests URL. You can check differences between two files with vscode