I'm writing a script to help update a small blog hosted on my website, but for some reason, when I request the HTML for the page, so that I can write it to memory and modify it, it seems to be spacing the lines out:
Expected:
<html>
<head>
<!-- <link rel="icon" href="/sort/this/later.jpg" type="image/x-icon" />-->
<title>foo</title>
<meta name="description" content="bar" />
What my script recieves:
<html>
<head>
<!-- <link rel="icon" href="/sort/this/later.jpg" type="image/x-icon" />-->
<title>foo</title>
<meta name="description" content="bar" />
I've tried stripping \n
and \r
characters from the response, but this doesn't seem to make any change whatsoever.
Edit: Sorry, I forgot to post the actual script itself. Here you go:
import neocities
import requests
import re
nc = neocities.NeoCities(api_key='[no]')
response = nc.info()
print(response)
htmlresponse = requests.get('https://thesite.com/index.html')
oldBlog = open('newindex.html', 'w')
oldBlog.write(str(htmlresponse.text).strip('\n').strip('\r'))
oldBlog.close()
with open('newindex.html', 'r') as blog:
contents = blog.readlines()
contents.insert(39,' <p class="header">test lol</p>\n'
' <p class="logpost">foobar</p>\n')
with open('newindex.html', 'w') as blog:
contents = "".join(contents)
blog.write(contents)
I know the method I'm using to strip the characters is incredibly janky, but I'm just doing it to see if it works. If it ends up working, I'll make it cleaner.
change
oldBlog.write(str(htmlresponse.text).strip('\n').strip('\r'))
to
oldBlog.write(str(htmlresponse.text).replace('\n', ''))