-2

I am a beginner so I apologize if my question is very obvious or not worded correctly.

I need to send a request to a URL so data can then be sent back in XLM format. The URL will have a user specific login and password, so I need to incorporate that as well. Also there is a port (port 80) that I need to include in the request. Is requests.get the way to go? I'm not exactly sure where to start. After receiving the XLM data, I need to process it (store it) on my machine - if anyone also wants to take a stab at that (I am also struggling to understand exactly how XLM data is sent over, is it an entire file?). Thanks in advance for the help.

  • 1
    google this or show us what you've tried, https://docs.python.org/2/library/httplib.html – depperm Jul 12 '16 at 20:31
  • 3
    What have you tried so far? Requests is probably the easiest way to do it. However, it seems like you're asking about a lot of concepts at once-- how HTTP / the web works in general, namely. Why not start there? – Kevin M Granger Jul 12 '16 at 20:33
  • here is a related post http://stackoverflow.com/questions/645312/what-is-the-quickest-way-to-http-get-in-python though it doesn't return xlm (do you mean xml?) – depperm Jul 12 '16 at 20:35
  • I did see that post but it doesn't have login info or is port specific. And yes, I still am learning exactly what I'm getting into here in terms of understanding requests and responses. Also, yes the file is XLM (excel), not XML. This is financial data. I still dont fully understand how an XLM file can be sent and received on my end with a response...anyway, the next step after figuring out the request is going to be figuring out how to receive and process the data. This is probably a complex problem for a noob but I'm giving it a shot. –  Jul 12 '16 at 20:40
  • ...maybe it is XML actually. I can figure that out down the road but for right now I'm just working on the request. Ill check out these links. Thanks. –  Jul 12 '16 at 20:59

2 Answers2

1

Here is a python documentation on how to fetch internet resources using the urllib package.

It talks about getting the data, storing it in a file, sending data and some basic authentication.

https://docs.python.org/3/howto/urllib2.html

Getting the URL would look something like this import

Import urllib.request
urllib.request.urlopen("http://yoururlhere.co.uk").read()

Note that this is for strings and Python 3 only. Python 2 version can be found here What is the quickest way to HTTP GET in Python?

If you want to parse the data you may want to use this https://docs.python.org/2/library/xml.etree.elementtree.html

I hope this helps! I am not too sure on how you would approach the username and password stuff but these links can hopefully provide you with information on how to do some of the other stuff!

Community
  • 1
  • 1
doodle911
  • 55
  • 2
  • 9
0

Import the requests library and then call the post method as follows:

 import requests


 data = {
       "email" : "netsparkertest@test.com",
       "password" : "abcd12333",
 }
 r = requests.post('www.facebook.com', data=data)
 print r.text
 print r.status_code
 print r.content
 print r.headers
Graham
  • 7,431
  • 18
  • 59
  • 84
Skiller Dz
  • 897
  • 10
  • 17