0x00 한

Programming

Making an Automatic Posting Macro for DC Inside!

While building a fan page and updating various things, I felt a need to promote it to attract visitors.

I wondered where promotion would be most effective, and since I thought there is no place like DC Inside for gathering visitors, I decided to make a macro that automatically writes posts there to promote the fan page! (Crawler bots collect DC Inside often, so let’s aim for search engine exposure as well!)

First, I decided to use selenium for the macro.

What is Selenium?

It is widely used as a web test automation tool, and it can access the result after rendering by JS is complete. In other words, it is a tool that lets you control a real browser.

#install selenium
$ sudo pip install selenium

#install configparser to use a config file
$ sudo pip install configparser

Once everything is ready, let’s make the macro in python!

I chose Chrome as the browser to use with selenium. To control Chrome with selenium, you need a Chrome driver.

https://sites.google.com/a/chromium.org/chromedriver/downloads (Added 2026-10: this address now redirects to a login page, so I changed the link to a January 2018 web archive copy.)

Download it from the address above and put it in the same path as the python code file.

# -*- coding: utf-8 -*- 
#write.py

from selenium import webdriver
import time
import configparser

Config = configparser.ConfigParser()

#load the config file
Config.read('./info.conf')
id = Config.get('dc', 'id')
pw = Config.get('dc', 'pw')

URL = 'http://www.dcinside.com'
GALL = 'http://gall.dcinside.com/board/write/?id=lovelyz'
options = webdriver.ChromeOptions()

#headless mode
options.add_argument('headless')
options.add_argument('window-size=1920x1080')
options.add_argument("disable-gpu")

#change the user-agent
options.add_argument("user-agent=Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36")

#load the Chrome driver
driver = webdriver.Chrome('./chromedriver', chrome_options=options)

driver.implicitly_wait(3)
#load the main page
driver.get(URL)
time.sleep(3)

#login section
driver.find_element_by_name('user_id').send_keys(id)
driver.find_element_by_name('password').send_keys(pw)
driver.find_element_by_id('login_ok').click()

#load the post writing page
driver.get(GALL)
time.sleep(3)

#post writing section
driver.find_element_by_name('subject').send_keys(u'1일 1러블리즈')
driver.find_element_by_id("tx_switchertoggle").click();
time.sleep(1)

driver.switch_to_frame(driver.find_element_by_xpath("//iframe[@name='tx_canvas_wysiwyg']"))
driver.find_element_by_tag_name("body").send_keys(u"<img src='http://sodeok.xyz/lovelyz.gif'><br><br><br><a href='http://lovelyzfan.xyz' target='_blank' class='tx-link'>러블리즈 이미지 갤러리</a>")

driver.switch_to_default_content()
driver.find_element_by_xpath("//input[@src='http://nstatic.dcinside.com/dgn/gallery/images/btn_save.gif']").click()
time.sleep(1)
driver.quit()

Then write the python code as above; the address stored in GALL is the post-writing address of the gallery I will promote in.

I plan to promote automatically 1 time a day from the server, so I add headless to the Chrome options.

The headless option lets you control the browser without the browser actually running visually. However, when the headless option is added, DC Inside forwards to another page, so I get around this by changing the user-agent. (When the headless option is used, headless is added to the user-agent, and DC Inside seems to filter on that. So I change the user-agent to look like a regular PC browser.)

The part to note is driver.switch_to_frame: on DC Inside, the post content is inside an iframe when writing, so I find the body (where the post content actually goes) through frame switching.

When writing a post, I made it promote the fan page link along with an image.

Delays are also placed in between so that the next action runs only after the page has loaded enough.

Now let’s run python write.py to check that the post is written properly!

Once you confirm the post is written properly, write a script that runs write.py every day at 00:00 in crontab on the server and add it!