3

Most certainly my question is not asked properly . Anyway, I am looking for a way to convert some data I ve extracted from the web to a list or a string (string would be better tho).

At the moment, this is what I wrote :

import urllib as web

message = "http://hopey.netfonds.no/posdump.php?date=20150209&paper=AAPL.O&csv_format=txt"   
data = web.urlopen(message)

data has a very weird type I ve never seen before (yes yes still new to that python thing). So any help would be very helpful .

Thanks in advance.

2
  • I am not that stoopid. Just wrote the thing too quickly. Obviousy Ive got the " in the string .... Commented Feb 12, 2015 at 19:59
  • 1
    I'm not sarcastic, reading a tutorial is a good thing that you can do. I'm still reading many tutorials, including basic ones. In your future posts, try to demonstrate minimal research efforts and we'll be glad to help you. Sorry if my post sounded sarcastic, I deleted it. Commented Feb 12, 2015 at 20:27

1 Answer 1

4

You can use the metod .read()

data = web.urlopen(message)
str_data = data.read()

This will return the html on the page. You can use dir(web.urlopen(message)) to see all the methods available for that object. You can use dir() to see the methods available for anything in python.

To sum up the answer, on that object you crated you can call the method .read() ( like data.read()) or you can use .readline( like data.readline(), this will read just a line from the file, you can use this method to read just a line when you need it).When you read from that object you will get a string back.

If you do data.info() you will get something like this :

<httplib.HTTPMessage instance at 0x7fceeb2ca638>

You can read more about this here .

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.