Codex Reference Material

Hi, Has anyone found a way to feed codex sample material to use?

For example, feed it a page source code to use as reference with a query. This could be used to allow me to say for example “Find all DIVs with role of ‘label’ that contain the word ‘Demo’ and remove them”.

Any help with this would be greatly appreciated.

1 Like

My experience with testing Codex is that the AI service generating “program code” based on your input (instruction). Based on what you are trying to achieve, I translate it into below description and then send it to Codex.

create a Python code to load source code of and remove all the div tags with its data-el-section attribute equals to “primary links” (similar to your request).

Below is the response from Codex with code-davinci-002 model.

import requests
from bs4 import BeautifulSoup

url = “

r = requests.get(url)
soup = BeautifulSoup(r.content, ‘html.parser’)

for div in soup.find_all(‘div’, attrs={‘data-el-section’: ‘primary links’}):


It works well.

Hi Nick, thanks for your reply although i should have been more specific.

I’m working with the Codex Javascript Sandbox and my first thought was very similar to what you’ve sugested. If I tell Codex at the start what site im looking at, eg:, it achieves the same end goal as feeding the source code of the site as “sample material” for it to work off.

The issue I have is im using it to develop on “offline” websites which are run on internal networks so they aren’t accessible to Codex via the public internet, hence why i was trying to feed it the source code as a work around. As far as i’m aware, there isnt any way for me to run codex locally.

Any help getting around this or finding a solution to this would be greatly appreciated!

Hi Bradley,
You can add soruce code to your instruction and ask Codex to use it.
This is how I instructed Codex and its response.

/* create a javascript to find all DIVs with role of ‘label’ that contain the word ‘Demo’ and remove them using below HTML code as an example.

<div role="label">Demo</div>
<div role="label">Hello</div>
<div role="label">World</div>


var divs = document.getElementsByTagName(“div”);
for (var i = 0; i < divs.length; i++) {
if (divs[i].getAttribute(“role”) == “label” && divs[i].innerHTML.indexOf(“Demo”) > -1) {

I think the key point is to describe what you wnat clearly and then Codex should be able to generate some useful code for you. If it doesn’t then change a way to describe what you want. Don’t just change few words, my experience is Codex will still create pretty much the same code again. Hope this helps.


Your scenario is mentioned in the best practice page " Provide examples for more precise results." section.

Code completion - OpenAI API