-
網(wǎng)頁(yè)下載器查看全部
-
URL 管理器實(shí)現(xiàn)方式查看全部
-
URL 管理器查看全部
-
基本知識(shí)框架查看全部
-
URL管理器三種實(shí)現(xiàn)方式:內(nèi)存;關(guān)系型數(shù)據(jù)庫(kù);緩存數(shù)據(jù)庫(kù)。 大公司多緩存數(shù)據(jù)庫(kù);個(gè)人或小公司,內(nèi)存即可,不夠用了或想永久儲(chǔ)存就用關(guān)系型數(shù)據(jù)庫(kù)。查看全部
-
URL管理器:至少支持的5個(gè)功能查看全部
-
簡(jiǎn)單爬蟲(chóng)架構(gòu)——運(yùn)行流程查看全部
-
爬蟲(chóng)調(diào)度端:?jiǎn)?dòng),停止,監(jiān)控運(yùn)行情況; URL管理器:管理待爬取和已爬取的URL; 網(wǎng)頁(yè)下載器:接收待爬取URL,將網(wǎng)頁(yè)內(nèi)容下載為字符串,給解析器; 網(wǎng)頁(yè)解析器:一方面解析出有價(jià)值的數(shù)據(jù),一方面解析出其他關(guān)聯(lián)URL,傳回URL管理器進(jìn)行循環(huán)。查看全部
-
爬蟲(chóng)簡(jiǎn)介查看全部
-
from baike_spider import url_manager, html_downloader, html_parser,\ html_outputer class SpiderMain(): def __init__(self): self.urls=url_manager.UrlManager() self.downloader=html_downloader.HtmlDownloader() self.parser=html_parser.HtmlParser() self.outputer=html_outputer.HtmlOutputer() def craw(self,root_url): count=1 self.urls.add_new_url(root_url) while self.urls.has_new_url():#如果有待爬去的url new_url=self.urls.get_new_url()#取出一個(gè) print 'craw %d:%s' %(count,new_url) html_cont=self.downloader.download(new_url) new_urls,new_data=self.parser.parse(new_url,html_cont) self.urls.add_new_urls(new_urls) self.outputer.collect_data(new_data) count=count+1 if count=1000 break self.outputer.output_html() if _name_=="__main__": root_url = "http://baike.baidu.com/view/21087.htm" obj_spider=SpiderMain() obj_spider.craw(root_url)查看全部
-
視屏中的練習(xí)程序 import urllib2 import cookielib import bs4 url = "http://www.baidu.com" print '11---------------------------' response1 = urllib2.urlopen(url) print response1.getcode() print len(response1.read()) print '22----------------------------' request = urllib2.Request(url) request.add_header("user-agent", "Mozilla/5.0") response2 = urllib2.urlopen(request) print response1.getcode() print len(response1.read()) print '33------------------------------' cj = cookielib.CookieJar() opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) urllib2.install_opener(opener) response3 = urllib2.urlopen(url) print response3.getcode() print len(response3.read()) print bs4查看全部
-
------------方法一 ---------------- #導(dǎo)入庫(kù) import urllib2 #openurl獲取url response = urllib2.openurl('http://www.xxx.com') #getcod獲取返回碼 print response.getcode() #讀取內(nèi)容 cont = response.read() --------------方法二-------------- import urllib2 #創(chuàng)建request對(duì)象 request = urllib2.Request(url) #添加數(shù)據(jù) request.add_data('a','1') #添加http的header request.add_header('User-Agent','Mozilla/5.0') #發(fā)送請(qǐng)求獲取結(jié)果 response = urllib2.urlopen(request) ------------方法三------------ import urllib2,cookielib #創(chuàng)建cookie容器 cj = cookielib.CookieJar() #創(chuàng)建1個(gè)opener opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) #給urllib2安裝opener urllib2.install_opener(opener) #使用帶有cookie的urllib2訪問(wèn)網(wǎng)頁(yè) response = urllib2.urlopen('http://www.xxx.com')查看全部
-
cookie查看全部
-
url管理器的實(shí)現(xiàn)查看全部
-
url管理器查看全部
舉報(bào)
0/150
提交
取消