sql - Storing a List into Python Sqlite3 -
i trying scrape form field ids using beautiful soup this
link in beautifulsoup(content, parseonlythese=soupstrainer('input')): if link.has_key('id'): print link['id']
lets assume returns like
username email password passwordagain terms button_register
i write sqlite3 db.
what doing down line in application is... use these form fields' ids , try post may be. problem is.. there plenty of sites form field ids have scraped. relation this...
domain1 - first list of form fields domain1 domain2 - second list of form fields domain2 .. , on
what unsure here is... how should design column kind of purpose? ok if create table 2 columns -
col 1 - domain url (as text) col 2 - list of form field ids (as text)
one thing remembered is... down line in application need this...
pseudocode
if domain "http://somedomain.com": ever item in col2 (which list of form field ids): assign set of values each of form fields & make post request
can 1 guide, please?
edited on 22/07/2011 - below database design correct?
i have decided have solution this. guys think?
i having 3 tables below
table 1
key column (auto generated integer) - primary key domain text
sample data like:
1 http://url1.com 2 http://url2.com 3 http://url3.com
table 2
domain (here using key number table 1) reglink - have registeration link (as text) form fields (as text)
sample data like:
1 http://url1.com/register field1 1 http://url1.com/register field2 1 http://url1.com/register field3 2 http://url2.com/register field1 2 http://url2.com/register field2 2 http://url2.com/register field3 3 http://url3.com/register field1 3 http://url3.com/register field2 3 http://url3.com/register field3
table 3
domain (here using key number table 1) status (as text) user (as text) pass (as text)
sample data like:
1 pass user1 pass1 2 fail user2 pass2 3 pass user3 pass3
do think table design good? or there improvements can made?
try ids:
ids = (link['id'] link in beautifulsoup(content, parseonlythese=soupstrainer('input')) if link.has_key('id'))
and should show how save them, load them, , each. uses single table , inserts 1 row each field each domain. it's simplest solution, , adequate relatively small number of rows of data.
from itertools import izip, repeat import sqlite3 conn = sqlite3.connect(':memory:') c = conn.cursor() c.execute('''create table domains (domain text, linkid text)''') domain_to_insert = 'domain_name' ids = ['id1', 'id2'] c.executemany("""insert domains values (?, ?)""", izip(repeat(domain_to_insert), ids)) conn.commit() domain_to_select = 'domain_name' c.execute("""select * domains domain=?""", (domain_to_select,)) # example def some_function_of_row(row): return row[1] + ' value' fields = dict((row[1], some_function_of_row(row)) row in c) print fields c.close()
Comments
Post a Comment