Skip to content

Instantly share code, notes, and snippets.

@Alexander-0x80
Created October 27, 2014 11:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alexander-0x80/5381d55c54c388876171 to your computer and use it in GitHub Desktop.
Save Alexander-0x80/5381d55c54c388876171 to your computer and use it in GitHub Desktop.
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