-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyiiDocScrap.py
More file actions
34 lines (32 loc) · 817 Bytes
/
Copy pathyiiDocScrap.py
File metadata and controls
34 lines (32 loc) · 817 Bytes
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
#-*- coding:utf-8 -*-
import os,sys
import requests
from lxml import etree
baseurl=sys.argv[1]
#baseurl='http://www.yiiframework.com/doc-2.0/'
clsName=sys.argv[2]
#clsName="list-group-item"
url=baseurl+'guide-index.html'
page=requests.get(url)
html=page.text
selector=etree.HTML(html)
content=selector.xpath('//a[@class="list-group-item"]/@href')
for c in content:
if c[0]=='.':
nav=c[2:]
url=baseurl+nav
elif c[0:4]=='http':
nav=c.split('\/')[:-1]
url=c
else:
nav=0
if nav:
fname="./yii/"+nav
if os.path.exists(fname):
print('%s exists'%hfile)
continue
hfile=open('./yii/'+nav,'w')
print('downloading %s\n'%hfile)
page=requests.get(url)
html=page.text
hfile.write(html)