def scrape_url(url):
#url = 'api-ref-compute-v2.1.html'
page = requests.get('http://developer.openstack.org/' + url)
tree = html.fromstring(page.content)
#Create a list of HTTP verbs
verbs = tree.xpath('//a[@class="operation-anchor"]/following::span[1]/text()')
operations = tree.xpath('//a[@class="operation-anchor"]/following::div[1]/text()')
#Match up Verbs and Operations and output a printed list
methods = zip(verbs, operations)
print len(verbs)
print len(operations)
if len(verbs) == len(operations):
for verbs, operations in methods:
print verbs + ' ' + operations
else:
print "Number of verbs doesn't match number of operations for ", page.url
评论列表
文章目录