import urllib.request
page = urllib.request.urlopen("http://www.randompickupline.com/")
text = page.read().decode("utf8")
where = text.find('<p id="pickupline">')
start_of_line = where + 18
end_of_line = start_of_line + 150
line = (text[start_of_line:end_of_line])
print (line)
This is a basic html import for a text based game I'm writing for fun, and I'm making a dynamic string. However, the string output is random (can vary from 25-132 characters). I'd like to know how to remove characters after the target text. The desired text output is red, and the characters I wish to remove are green:
<h1>Pickup Line</h1><p id="pickupline">Look at my lips and your lips. They want to massage each other.</p>
<p id="directlink"><a href="http://www.randompickupline.com/pickupline.php?zid=1089" target="new">Direct link to this line: http://www.randompickupline.com/pickupline.php?zid=1089</a><br /></p>