-
Notifications
You must be signed in to change notification settings - Fork 10
/
jiandan.py
37 lines (31 loc) · 1.04 KB
/
jiandan.py
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
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from bs4 import BeautifulSoup
import os
from Download import request
import thread
class jiandan():
def get(self, url):
html = request.get(url, 3)
return html.text
def save(self, url):
html = self.get(url)
soup = BeautifulSoup(html, 'lxml')
tag_all = soup.find_all('div', class_='text')
for tag in tag_all:
img_url = tag.find('img')['src']
if cmp(img_url[0:5],'http:'):
img_url = img_url[7:]
elif cmp(img_url[0:2], '////'):
img_url = img_url[2:]
else :
continue
[filename, filetype] = img_url.split('/')[-1].split('.')
with open('/media/wangs/Docs/pic/jiandan/{}.{}'.format(filename, filetype), 'wb') as img:
img.write(request.get('http://'+img_url, 3).content)
img.close()
for i in range(3, 2353):
url = 'http://jandan.net/ooxx/page-{}#comments'.format(i)
print url
jd = jiandan()
jd.save(url)