-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhtmlparse_test.py
More file actions
38 lines (31 loc) · 1.12 KB
/
htmlparse_test.py
File metadata and controls
38 lines (31 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# -*- coding: utf-8 -*-
import urllib
from lxml import etree
# url = 'https://www.python.org/events/python-events/'
# f_handle = urllib.urlopen(url)
# data = f_handle.read()
# html = etree.HTML(data)
# nodes = html.xpath('//ul[@class="list-recent-events menu"]/li')
# for node in nodes:
# time = node.xpath('p/time/text()')
# zt = node.xpath('h3[@class="event-title"]/a/text()')
# address = node.xpath('p/span[@class="event-location"]/text()')
# data = {'time':time,'zt':zt,'address':address}
# print data
# url = 'https://docs.python.org/3/faq/'
# fHandle = urllib.urlopen(url)
# result = fHandle.read()
# html = etree.HTML(result)
# nodes = html.xpath('//div[@class="toctree-wrapper compound"]/ul/li')
# L = []
# for node in nodes:
# L.append(node.xpath('a/text()')[0])
# print L
url = "http://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=0&rsv_idx=1&tn=baidu&wd=a&rsv_"
fhandle = urllib.urlopen(url)
result = fhandle.read()
html = etree.HTML(result)
nodes = html.xpath('//div[@id="content_left"]/div')
for node in nodes:
print node.xpath('h3/a/text()')
print len(nodes)