Jump to content
UBot Underground

xindexer

Fellow UBotter
  • Content Count

    3
  • Joined

  • Last visited

Posts posted by xindexer

  1. I spent the last couple of days figuring out how to scrape articles and drop them directly into my database and I thought that I would share what I have learned.

     

    I'm going to assume that you have an instance of mysql up and running either locally or on a server somewhere and that you can connect to it.

     

    I have a very basic setup with two tables, "articles" and "keywords"

     

    The articles table has "ID, keyword, title, article" as columns and the keywords table has "ID, keyword'

     

    I have prepopulated the keywords table with several thousand keywords to pull from

     

    First up - query the database for the keyword and put it into a variable

     

    plugin command("DatabaseCommands.dll", "connect to database", "server=localhost;uid=****; pwd=****; database=articles; port=3306; pooling=false") {
     plugin command("DatabaseCommands.dll", "query with results", "SELECT keyword from keywords order by rand() limit 1", #keyword)
    }
    

     

     

    The trick to getting data back into the database is that you need to escape your input. In other words you need to change ' to \' and " to \"

     

    This took me a bit to figure out the syntax so here it is:

     

    set(#article, $replace(#article, "'", "\\\'"), "Global")
    set(#article, $replace(#article, "\"", "\\\""), "Global")
    

     

    notice that it takes three \\\ in order to get one \ on the output - this has to do with special characters (you also need to escape the " in the replace line in order for the system to be able to find the " because both " and \ are special characters)

     

    Finally, to insert into the database - you need to use this format {#keyword}

     

    plugin command("DatabaseCommands.dll", "connect to database", "server=65.39.148.178;uid=writer; pwd=owgn2wby;database=articles; port=3306; pooling=false") {
     plugin command("DatabaseCommands.dll", "query","INSERT INTO articles (keywordID,title,article) VALUES ('{#keyword}','{#title}','{#article}');")
    }
    

     

    hope this helps somebody out in the future

    • Like 4
×
×
  • Create New...