In [133]:
import requests
import bs4
import getpass

import arrow
In [105]:
myusr = getpass.getuser()
In [2]:
resulreq = requests.get('')
In [7]:
bssou = bs4.BeautifulSoup(resulreq.text)
/usr/local/lib/python3.4/dist-packages/bs4/ UserWarning: No parser was explicitly specified, so I'm using the best available HTML parser for this system ("lxml"). This usually isn't a problem, but if you run this code on another system, or in a different virtual environment, it may use a different parser and behave differently.

The code that caused this warning is on line 170 of the file /usr/lib/python3.4/ To get rid of this warning, change code that looks like this:


to this:

 BeautifulSoup(YOUR_MARKUP, "lxml")

In [36]:
testlis = list()
In [134]:
for sso in (bssou.findAll('select')):
    for sf in (sso.findAll('option')):
#        print(sf)
In [76]:
letes = len(testlis) - 1

want api of each electorate.

name: Auckland Central id: 1 candinates: name: votes, party

In [125]:
In [126]:
timnow =
In [132]:
for somerol in range(10,letes):
    reqid = requests.get('{}.html'.format(somerol))

    reqtxt = bs4.BeautifulSoup(reqid.text, 'lxml')
    elebody = (reqtxt.find('tbody'))
        with open('/home/{}/electionresults/posts/results-{}.md'.format(myusr, somerol), 'w') as resulmd:
            resulmd.write(str(somerol) + ' \n' + str(elebody.text))
        with open ('/home/{}/electionresults/posts/{}.meta'.format(myusr, somerol), 'w') as opmetat:
            #for arage in alltags:
            #    print(arage)
            opmetat.write('.. title: {}\n.. slug: {}\n.. date: {}\n.. tags: \n.. link:\n.. description:\n.. type: text'.format(somerol, somerol, timnow.for_json()))

    except AttributeError: 
    #     None not in elebody:
    #    with open('/home/pi/memetest/posts/results-{}.md'.format(somerol), 'w') as resulmd:
    #        resulmd.write(str(elebody.text))
In [ ]:
In [70]:
#reqid = requests.get('{}.html'.format(inid))

#reqtxt = bs4.BeautifulSoup(reqid.text, 'lxml')
In [71]:
#elebody = (reqtxt.findAll('tbody'))
In [72]:
#someresul = list()
In [135]:
#for ele in elebody:
#    someresul.append(ele.text)
In [15]:
#tbodz = bssou.findAll('td', {'class': 'text-left bold'})
In [108]:
bsu = bssou.findAll('td')
In [122]:
with open('/home/{}/electionresults/stories/'.format(myusr), 'w') as stopn:
    for bs in bsu:
In [ ]:
#with open('/home/pi/memetest/posts/results-{}.html'.format(inid, 'w') as resulmd:
#    resulmd.write(elebody)


Comments powered by Disqus