Functions
There are several general function available in the framework.
A short overview below:
Fetch an Url
-
ba.FetchUrl(url, cacheTime, xhr, params)
A function to get a http request, so you can fetch the html content of a specific website. It has the option to cache the results to release the load on internet servers. If the variable cachetime is set it will automatically loads the page from the cache instead of the internet as long as the cache is not expired yet. It is using a GET request on default.
Note that the caching of a page speeds up the loading time, but also is adding information to the database and extending the disk usage. For boxee 0.9 users this is no problem but the boxee box has a limited amount of space available. So please use the cache function appropriate.
Passing variables:
| Variable | Type | Description | Needed |
| url | string | The path to the website | Yes |
| cacheTime | integer | Time period to keep the http data in cache (in seconds) | No |
| xhr | Boolean [True,False] | Send the request as ajax xhr | No |
| params | string | Use POST request with params (var=test&var2=test2) | No |
Examples:
-
# GET request
-
path = "http://www.google.com"
-
data = ba.FetchUrl(path)
-
-
# GET request with params
-
path = "http://www.google.com?search=boxee&var=delta"
-
data = ba.FetchUrl(path)
-
-
# GET request cached for 60 minutes
-
path = "http://www.google.com"
-
data = ba.FetchUrl(path, 3600)
-
-
# XHR ajax call not cached
-
path = "http://www.google.com"
-
data = ba.FetchUrl(path, 0, True)
-
-
# POST Request not cached
-
path = "http://www.google.com"
-
params = "search=boxee&var=delta"
-
data = ba.FetchUrl(path, 0, False, params)
-
-
# POST Request cached for 5 minutes
-
path = "http://www.google.com"
-
params = "search=boxee&var=delta"
-
data = ba.FetchUrl(path, 300, False, params)
Set User Agent
-
ba.UserAgent(var):
A function to set the user agent of the http requests
Passing variables:
| Variable | Type | Description | Needed |
| var | string | User agent string | Yes |
BeautifulSoup
-
BeautifulSoup(data):
A very usefull parser to parse xml or html data.
It transforms the string into variables that can be searched or called. For more information regarding BeautifulSoup please read the manual on crummy.com
Main variables:
| Variable | Type | Description | Needed |
| data | string | A string with html / xml data | Yes |
Examples:
-
doc = [‘<html><head><title>Page title</title></head>’,
-
‘<body><p id="firstpara" align="center">This is paragraph <b>one</b></p>’,
-
‘<p id="secondpara" align="blah">This is paragraph <b>two</b></p></body>’,
-
‘</html>’]
-
soup = BeautifulSoup(”.join(doc))
-
-
soup.head.title
-
# <title>Page title</title>
-
-
soup.body.p.b.string
-
# u’one’
-
-
soup.findAll([‘title’, ‘p’])
-
# [<title>Page title</title>,
-
# <p id="firstpara" align="center">This is paragraph <b>one</b>.</p>,
-
# <p id="secondpara" align="blah">This is paragraph <b>two</b>.</p>]
-
doc = [‘<html><head><title>Page title</title></head>’,
-
‘<body><p id="firstpara" align="center">This is paragraph <b>one</b></p>’,
-
‘<p id="secondpara" align="blah">This is paragraph <b>two</b></p></body>’,
-
‘</html>’]
-
soup = BeautifulSoup(”.join(doc))
-
-
for info in soup.findAll(‘p’):
-
# create your boxee list at this point and extract data from the p tag
-
# example info.b.contents[0] will result in ‘one’ and in the second list in ‘two’
Didn't find any related posts :(
bartsidee
nl