5

Assuming that I have a condition, like all the questions that were asked in February 2019, or I have their question ID.

Is it possible to get the original question body HTML (before it was edited by the asker or the community)?

I tried looking at the Data Explorer and the Stack Overflow API, but I can't find a good solution.

3
  • 1
    Are you trying to search through multiple questions by their HTML or do you just need to get the source of any specific question, e.g. by visiting the revision histroy? Commented Jul 19, 2020 at 10:53
  • See the public documentation of the schema for the Data Explorer. You can look up the post by the post ID, and then retrieve its Body, which is the rendered HTML.
    – Cody Gray Mod
    Commented Jul 19, 2020 at 10:58
  • 2
    You can only get the original Markdown. See the PostHistory table, Text column for rows with posthistorytypeid in (2,5,8) and PostId if you want a specific post. The server-side rendered html is not kept in the public schema.
    – rene
    Commented Jul 19, 2020 at 11:17

2 Answers 2

6

No, you can't get the original HTML from the question but you can get the Markdown that was posted for each revision. See When does the question/answer text get converted from markdown to html

This simple query does that for a single post:

select creationdate
     , text
     , name
from posthistory ph
inner join posthistorytypes pht on pht.id = ph.posthistorytypeid
where postid = ##postid?53334142##
and posthistorytypeid in (2,5,8)
order by creationdate

Or if you want posts created at a certain date:

select ph.creationdate
     , text
     , name
     , concat('site://q/',p.id, '|', coalesce(p.title, convert(nvarchar,p.id))) [Link] 
from posthistory ph
inner join posthistorytypes pht on pht.id = ph.posthistorytypeid
inner join posts p on ph.postid = p.id
where p.creationdate between '##startdate?2019-02-14##' and '##enddate?2019-02-15##'
and posthistorytypeid in (2,5,8)
order by ph.creationdate

The rendered HTML is only stored in the Posts table Body column and that is always the latest version. No history is kept of the prior rendered HTML.

If you have the Markdown you can run it yourself through the MarkdownSharp processor to get the HTML that is most likely what it would have been on the site at the time of posting.

The Database schema is documented in Database schema documentation for the public data dump and SEDE

The relevant tables you find in the Stack Exchange Data Dump are similar to what you find in SEDE. The Data Dump is refreshed every 3 months. So by downloading all data dumps from the Quarter you're interested in till now, will give you more "history" data but still at a 3 months interval.

SEDE is updated on Sunday. It does come with a tutorial written by the unforgettable Monica Cellio. We have a SEDE Chatroom

4
  • maybe there is a dump for the original html in the published dumps?
    – Matan
    Commented Jul 19, 2020 at 11:31
  • @Matan the dump is almost identiical and only updated every 3 months. But yes, in theory you could get for some posts the HTML of earlier revisions from the posts table.
    – rene
    Commented Jul 19, 2020 at 11:36
  • what do you mean by "some posts" let's say that i need the posts from 2019. i get get them? or only those who weren't edited before the dump was made? what is the limitation?
    – Matan
    Commented Jul 19, 2020 at 11:40
  • @Matan the limitation is that ONLY the markdown is kept as revision history in both SEDE, the datadump and the API, not the rendered HTML. You can download earlier datadumps from the WebArchive from say the first quarter of 2019 but if a post got edited before end of march 2019 you'll still not be able to find the original html because that has been regenerated by newer revisions. There is no history kept anywhere for rendered HTML.
    – rene
    Commented Jul 19, 2020 at 11:54
1

There is no "original HTML" of a question because questions are written in Markdown. If you want to see the Markdown source, you can use the procedure described in this answer.

Of course, you can get the HTML rendering of a question by converting the source yourself. there are great tools for that, like Pandoc.

You can also write this in the browser's JavaScript console to get the HTML that the browser uses, but note that it might include banners (like those in closed and locked questions) and <span> elements used for syntax highlighting:

document.querySelector("#question .post-text").innerHTML
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .