File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # -*- coding: utf-8 -*-
2+ import urllib
3+ from lxml import etree
4+
5+
6+ # url = 'https://www.python.org/events/python-events/'
7+ # f_handle = urllib.urlopen(url)
8+ # data = f_handle.read()
9+ # html = etree.HTML(data)
10+ # nodes = html.xpath('//ul[@class="list-recent-events menu"]/li')
11+ # for node in nodes:
12+ # time = node.xpath('p/time/text()')
13+ # zt = node.xpath('h3[@class="event-title"]/a/text()')
14+ # address = node.xpath('p/span[@class="event-location"]/text()')
15+
16+ # data = {'time':time,'zt':zt,'address':address}
17+ # print data
18+
19+
20+ # url = 'https://docs.python.org/3/faq/'
21+ # fHandle = urllib.urlopen(url)
22+ # result = fHandle.read()
23+ # html = etree.HTML(result)
24+ # nodes = html.xpath('//div[@class="toctree-wrapper compound"]/ul/li')
25+ # L = []
26+ # for node in nodes:
27+ # L.append(node.xpath('a/text()')[0])
28+ # print L
29+
30+
31+ url = "http://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=a&rsv_"
32+ fhandle = urllib .urlopen (url )
33+ result = fhandle .read ()
34+ html = etree .HTML (result )
35+ nodes = html .xpath ('//div[@id="content_left"]/div' )
36+ for node in nodes :
37+ print node .xpath ('h3/a/text()' )
38+ print len (nodes )
You can’t perform that action at this time.
0 commit comments