[Tutor] Coding question

Erin Anderson anders_e3 at denison.edu
Sat Nov 28 11:31:18 EST 2020


Hello, I am trying to figure out how to code for reading in text from a URL in python but in two chunks.

I am looking at a transcript from a website and I want to read in the text but I want the reading in of the text to stop when the transcript says “Part 2”, I then want to have this chunk of information as one entity and then create another entity filled with the text that occurs after the words “Part 2”. Im thinking one way to do this is using a while loop, but I am not quite sure how to implement it

Def text_chunk(url)
	webpage=web.urlopen(url)
	while text != “Part 2”:
		rawbytes=webpage.read()
		webpage.close()
		text = rawBytes.decode('utf-8’)
	return text

Thank you!!!!


More information about the Tutor mailing list