diff --git a/README.md b/README.md index 8df0858..9540b6e 100644 --- a/README.md +++ b/README.md @@ -16,3 +16,6 @@ **技术选型** - python version 2.7.11 - python version 3.4.0 + + +http://ns.giit.us/htm_data/7/1706/2470604.html \ No newline at end of file diff --git a/WebScrapingWithPython/python-scraping b/WebScrapingWithPython/python-scraping new file mode 160000 index 0000000..cec78b7 --- /dev/null +++ b/WebScrapingWithPython/python-scraping @@ -0,0 +1 @@ +Subproject commit cec78b7cadf16f45249c443248f918d6efaee6d3 diff --git a/WebScrapingWithPython/remark b/WebScrapingWithPython/remark index a2051d1..6df378d 100644 --- a/WebScrapingWithPython/remark +++ b/WebScrapingWithPython/remark @@ -62,3 +62,31 @@ Tesseract 文档: https://github.com/tesseract-ocr/tesseract/wiki EditThis cookie http://www.editthiscookie.com + + +分布式计算 distributed computing +Tor代理服务器 + +PySocks python 代理服务器通信模埠 https://pypi.python.org/pypi/PySocks + +搜索引擎优化: Search Engine Optimization,SEO + robots.txt + +机器人排除标准: Robots Exclusion Standard robots.txt + + +# +# robots.txt for PHPWIND BOARD +# Version 5.x +# + +User-agent: * +Disallow: /admin/ +Disallow: /require/ +Disallow: /hack/ +Disallow: /attachment/ +Disallow: /images/ +Disallow: /data/ +Disallow: /ipdata/ +Disallow: /template/ + diff --git a/WebScrapingWithPython/yaoshe1/index.py b/WebScrapingWithPython/yaoshe1/index.py new file mode 100644 index 0000000..53368a4 --- /dev/null +++ b/WebScrapingWithPython/yaoshe1/index.py @@ -0,0 +1,115 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# @Filename: index +# @Date : 2017-09-14 23:15 +# @Author : zzl +""" + python_version 2.7.11 + + import package: bs4,requests,html5lib + +""" +from urllib2 import urlopen +# from urllib2 import open +from bs4 import BeautifulSoup +import requests +# import urllib +import re +import os + +downLoadFile = 'D:\\happy\\yaoshe6' ##要下载到的目录 +isdebug = True + + +def getFile(url): + if(requests.get(url).status_code == 404): + print('这是个错误网址') + return [] + #print ('正在打开 ',url) + file_name = url.split('/')[-1] + file_s = downLoadFile + file_name + if os.path.exists(file_s): + print("file exists = " + file_name) + return + u = urlopen(url) + # u = requests.urlopen(url) + + f = open(file_s, 'wb') + + block_sz = 8192 + while True: + buffer = u.read(block_sz) + if not buffer: + break + + f.write(buffer) + f.close() + print("Sucessful to download = " + file_name) + +def getHtml(url): + page = urlopen(url) + html = page.read() + page.close() + return html + +# compile the regular expressions and find +# all stuff we need +def getUrl(html): + reg = r'(?:href|HREF)="?((?:http://)?.+?\.pdf)' + url_re = re.compile(reg) + url_lst = re.findall(url_re,html) + return(url_lst) + +def opeVideoUrl(url): + html = urlopen(url).read() + ss = html.replace(" ","") + urls = re.findall(r"(http://www.yaoshe2.com/get_file/.*?mp4).*?",ss,re.I) + for i in urls: + print(i) + # try: + getFile(i); + # except Exception,e: + # print e.message + # else: + # print 'this is over' + # bsObj = BeautifulSoup(html, "html5lib") + # print bsObj + +def eachLatestUpdates(): + currPage = 2 + print "eachLatestUpdates" + while currPage < 100: + startOpenPage("http://www.yaoshe6.com/latest-updates/" + str(currPage) + "/") + currPage = currPage + 1 + + + + +def startOpenPage(url): + print "base url ============== " + url + html = urlopen(url) + if isdebug == True: + print(html.read()) + bsObj = BeautifulSoup(html, "html5lib") + itemsDivObj = bsObj.findAll("div",{"class":re.compile("^(item)((?!:).)*$")}) + print "itemsDivObj div item = ",len(itemsDivObj) + for obj in itemsDivObj: + videosObjs = obj.findAll("a",{"href":re.compile("^(http://www.yaoshe6.com/videos/)((?!:).)*$")}) + print "videosObjs a videos = ",len(videosObjs) + if len(videosObjs) != 0: + strHref = videosObjs[0].attrs["href"] + # print strHref + count = 0 + while count < 1: + count = count+1 + print("url = " + strHref) + opeVideoUrl(strHref) + + +startOpenPage("http://www.yaoshe6.com/") +eachLatestUpdates() + + + + + diff --git a/WebScrapingWithPython/yaoshe1/index2.py b/WebScrapingWithPython/yaoshe1/index2.py new file mode 100644 index 0000000..2d4c4b3 --- /dev/null +++ b/WebScrapingWithPython/yaoshe1/index2.py @@ -0,0 +1,74 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# @Filename: index +# @Date : 2017-09-14 23:15 +# @Author : zzl +""" + python_version 2.7.11 +""" +from urllib2 import urlopen +# from urllib2 import open +from bs4 import BeautifulSoup +# import urllib +import re + +def getFile(url): + file_name = url.split('/')[-1] + u = urlopen(url) + f = open(file_name, 'wb') + + block_sz = 8192 + while True: + buffer = u.read(block_sz) + if not buffer: + break + + f.write(buffer) + f.close() + print "Sucessful to download" + " " + file_name + +def getHtml(url): + page = urlopen(url) + html = page.read() + page.close() + return html + +# compile the regular expressions and find +# all stuff we need +def getUrl(html): + reg = r'(?:href|HREF)="?((?:http://)?.+?\.pdf)' + url_re = re.compile(reg) + url_lst = re.findall(url_re,html) + return(url_lst) + +def opeVideoUrl(url): + html = urlopen(url).read() + ss = html.replace(" ","") + urls = re.findall(r"(http://www.yaoshe1.com/get_file/.*?mp4).*?",ss,re.I) + for i in urls: + print i + getFile(i); + # else: + # print 'this is over' + # bsObj = BeautifulSoup(html, "html5lib") + # print bsObj + + +html = urlopen("http://www.yaoshe1.com/") +# print(html.read()) +bsObj = BeautifulSoup(html, "html5lib") +itemsDivObj = bsObj.findAll("div",{"class":re.compile("^(item)((?!:).)*$")}) +for obj in itemsDivObj: + videosObjs = obj.findAll("a",{"href":re.compile("^(http://www.yaoshe1.com/videos/)((?!:).)*$")}) + # print("==================") + strHref = videosObjs[0].attrs["href"] + # print strHref + count = 0 + while count < 1: + count = count+1 + print("url = " + strHref) + opeVideoUrl(strHref) + + + + diff --git a/web_crawle/book/demo1.py b/web_crawle/book/demo1.py new file mode 100644 index 0000000..74239fa --- /dev/null +++ b/web_crawle/book/demo1.py @@ -0,0 +1,94 @@ +#!/usr/bin/python +# -*- coding: UTF-8 -*- +# @Filename: demo1 +# @Date : 2017-09-24 11:32 +# @Author : zzl +# from http://blog.csdn.net/actanble/article/details/52347458 + +""" + python_version 3.4 +""" +import re +import urllib.request as request +from bs4 import BeautifulSoup +import requests + +'''全局变量声明, 下载其它小说请注意修改 [下载到的本地目录, 书号, 起始index号]''' +downLoadFile = 'G:\\github.com\\python\\web_crawle\\book\\' ##要下载到的目录 +shuhao = '2_2970' ## 书号就是http://www.biquge.com/2_2970/2456497.html; com后面的那个。 +start, end = 2456497,100000 + +def setSrr(url): + if(requests.get(url).status_code == 404): + print('这是个错误网址') + return [] + print ('正在打开 ',url) + + l = [] + '''''请求响应和不响应的处理''' + response = request.urlopen(url) + + html = response.read() + soup = BeautifulSoup(html,"html5lib") + item = soup.findAll('h1') + title = re.match(r'(.*)