Skip to content

Instantly share code, notes, and snippets.

@brchiu
Last active March 8, 2020 11:08
Show Gist options
  • Save brchiu/91aa4ac49f024b564d18b50bed2d492f to your computer and use it in GitHub Desktop.
Save brchiu/91aa4ac49f024b564d18b50bed2d492f to your computer and use it in GitHub Desktop.
simple proof of concept for parsing Fibonacci Number web page
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from lxml import html
import requests
def get_fibonacci(idx):
r = requests.get('http://www.protocol5.com/Fibonacci/' + str(idx) + '.htm')
t = html.fromstring(r.content.decode('utf8'))
li_elms = t.xpath("//*[contains(@class, 'number-result')]/li")
for li in li_elms:
if li.xpath('h4/text()')[0].startswith('Decimal'):
print(li.xpath('div/text()')[0])
def main():
response = requests.get('http://www.protocol5.com/Fibonacci')
tree = html.fromstring(response.content.decode('utf8'))
numbers = tree.xpath("//*[contains(@class, 'fibonacci')]/a/text()")
for idx in range(len(numbers)):
get_fibonacci(idx)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment