Sunday, March 20, 2016

Re: Entering initial data into django database


Thanks ludovic, here is my code for the scraper..




 
from .models import Betting

import re
import requests
import urllib
from bs4 import BeautifulSoup


urls
= "https://sms.betyetu.co.ke/tomorrow.html"
htmlfile
= urllib.urlopen(urls)
htmltext
= htmlfile.read()
soup
= BeautifulSoup(htmltext, "html.parser")


for i in soup.findAll("table"):
   
print i.contents[1].contents[1].findAll("th")[0].text
   
print i.contents[1].contents[3].findAll("th")[0].text


   
   


       
   
try:
        momo
= 1
        a
= len( i.contents[3].contents)
       
while momo <= a:
           
print i.contents[3].contents[momo].findAll("td")[2].text
           
            foo
= Betting(matches=i.contents[3].contents[momo].findAll("td")[2].text)
           
            momo
+= 2

           
            foo
.save()
           

       
   
   
except:
        momo
= 1



   



I have a model called "betting" which has only one field "matches"..For it to work, I have placed it in init.py which is a wrong way to do it..Wanted to understand where this code should be placed..ie..which file and how to interact with it


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/d3677ab5-06eb-47aa-bdf8-d789a4c454b7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment