Created
October 27, 2014 11:34
-
-
Save Alexander-0x80/5381d55c54c388876171 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from bottle import Bottle, get, run | |
from bs4 import BeautifulSoup | |
@get("/search/<keyword>") | |
def search(keyword): | |
payload = {"q": keyword} | |
page = requests.get("http://www.bbc.co.uk/search", params=payload) | |
soup = BeautifulSoup(page.text) | |
articles = soup.find_all("article") | |
result = "<html><body>" | |
for article in articles: | |
result += "<li>" | |
result += "<h1>{}</h1>".format(article.h1.text.encode("utf-8")) | |
result += "<p>{}</p>".format(article.p.text.encode("utf-8")) | |
result += "</li></body></html>" | |
return result | |
run(host="localhost", port=8081, reloader=True) | |
# now point your browser to : http://localhost:8081/search/cyprus |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment