How can store scraped data (by beautifulsoup) in my models

Viewed 372

I have scraped data using beautifulsoup now i want to that scraped data in my models(in my postgresql) How i use this scraped data My models.py

from __future__ import unicode_literals
from django.db import models
from datetime import datetime  
class AppDetail(models.Model):
    name=models.CharField(max_length=50,blank=True,null=True,verbose_name='name*')
    image=models.ImageField(blank=True,null=True,upload_to='/home/cp/Documents/nApp/appstore/media')
    icon=models.ImageField(blank=True,null=True,verbose_name='icon*')
    host=models.CharField(max_length=50,blank=True,null=True)
    categories=models.ForeignKey(Category,blank=True, null=True ,verbose_name='categories*')
    description_of_app=models.TextField(max_length=5000,blank=True,null=True,verbose_name='description_of_app*')
    no_of_download=models.IntegerField(default=0,blank=True,null=True)
    whats_new=models.TextField(max_length=1000,blank=True,null=True)
    additional_information=models.ForeignKey(AdditionalInformation,blank=True,null=True)
    price=models.FloatField(null=True, blank=True)
    size=models.CharField(max_length=50,blank=True,null=True,verbose_name='size*')
    app_priority=models.IntegerField(default=0,blank=True,null=True,verbose_name='app_priority*')
    url=models.URLField(blank=True,null=True)
    is_active=models.BooleanField(default=True)
    image_url = models.URLField(null=True, blank=True)

my scrap.py

import urllib2
from bs4 import BeautifulSoup
import re
from appdetail.models import *

page = urllib2.urlopen('https://play.google.com/store/apps/details?id=com.igg.clashoflords2&hl=en').read()
soup = BeautifulSoup(page,'html.parser')
"""-----------For app name------------"""

for anchor in soup.findAll('div', {'class': 'id-app-title'}):

    app_name=anchor.text
    print anchor.text
    m=AppDetail.objects
    m.name=app_name
    m.save()

i want to use scrap "name" detail in my model name

0 Answers
Related