[英]How to populate a Django sqlite3 database
我的计划是分批从网站收集律师传记数据,然后将每批文件转换为.csv文件,然后转换为json,然后再将其加载到Django数据库中。
请让我知道如何以最佳方式完成这项任务。
只需直接加载数据库。 批量从网站收集数据,直接加载SQlite3。 只需编写使用Django ORM的简单批处理应用程序即可。 从网站收集数据并立即加载SQLite3。 不要创建CSV。 不要创建JSON。 不要创建中间结果。 不要做任何额外的工作。
编辑。
from myapp.models import MyModel
import urllib2
with open("sourceListOfURLs.txt", "r" ) as source:
for aLine in source:
for this, the, the_other in someGenerator( aLine ):
object= MyModel.objects.create( field1=this, field2=that, field3=the_other )
object.save()
def someGenerator( url ):
# open the URL with urllib2
# parse the data with BeautifulSoup
yield this, that, the_other
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.