Skip to content

Instantly share code, notes, and snippets.

@boffbowsh
Created November 8, 2016 08: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 boffbowsh/be5b64f0136a68314c05480eb776e9cf to your computer and use it in GitHub Desktop.
Save boffbowsh/be5b64f0136a68314c05480eb776e9cf to your computer and use it in GitHub Desktop.
from sys import argv
from bs4 import BeautifulSoup
import requests
if __name__ == "__main__":
search = requests.get("https://www.gov.uk/api/search.json?q=%s&filter_format%%5B%%5D=answer" % argv[1])
for result in search.json()["results"]:
answer = requests.get("https://www.gov.uk%s" % result["link"])
soup = BeautifulSoup(answer.text, 'html.parser')
highlight = soup.find_all('div', class_="highlight-answer")
if highlight:
print result["link"]
print highlight[0].text
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment