課程
/后端開(kāi)發(fā)
/Python
/Python開(kāi)發(fā)簡(jiǎn)單爬蟲(chóng)
craw 1 : http://baike.baidu.com/view/21087.htmcraw failed
2016-05-14
源自:Python開(kāi)發(fā)簡(jiǎn)單爬蟲(chóng) 7-7
正在回答
希望對(duì)你有所幫助
我的也是這樣的,代碼改了一遍,還是沒(méi)用,求大神指點(diǎn)
慕花花
慕粉3136486
代碼敲錯(cuò)了
ohyes768
import re
import urlparse
from bs4 import BeautifulSoup
class HtmlParser(object):
? ? def _get_new_urls(self,page_url,soup):
? ? ? ? new_urls=set()
? ? ? ? links=soup.find_all('a',href=re.compile(r"/view/\d+\.htm"))
? ? ? ? for link in links:
? ? ? ? ? ? new_url=link['href']
? ? ? ? ? ? new_full_url=urlparse.urljoin(page_url,new_url)
? ? ? ? ? ? new_urls.add(new_full_url)
? ? ? ? return new_urls
? ? def _get_new_data(self,page_url,soup):
? ? ? ? res_data={}
? ? ? ? #url
? ? ? ? res_data['url']=page_url
? ? ? ??
? ? ? ? #<dd class="lemmaWgt-lemmaTitle-title"><h1>Python</h1>
? ? ? ? title_node=soup.find('dd',class_="lemmaWgt-lemmaTitle-title")
? ? ? ? res_data['title']=title_node.get_text()
? ? ? ? #<div class="lemma-summary" >
? ? ? ? summary_node=soup.find('div',class_="lemma-summary")
? ? ? ? res_data['summary']=title_summary.get_text()
? ? ? ? return res_data
? ? def parse(self,page_url,html_cont):
? ? ? ? if page_url is None or Html_cont is None:
? ? ? ? ? ? return
? ? ? ? soup=BeautifulSoup(html_cont,'html.parser',from_encoding='utf-8')
? ? ? ? new_urls=self._get_new_urls(page_url,soup)
? ? ? ? new_data=self._get_new_data(page_url,soup)
? ? ? ? return new_urls,new_data
代碼就是按照視頻敲的,不知道哪錯(cuò)了
熊孩子3657953
我也是這樣的
我之前也是這樣的 ?不過(guò)現(xiàn)在解決了 應(yīng)該是html_parser.py 有問(wèn)題,找找代碼是不是有錯(cuò)誤,或者你把代碼貼上來(lái) ,我?guī)湍阏艺??,我也是早上剛找到的錯(cuò)誤
我也是這樣的 ?請(qǐng)問(wèn)你解決了嗎?
舉報(bào)
本教程帶您解開(kāi)python爬蟲(chóng)這門(mén)神奇技術(shù)的面紗
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢(xún)優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2016-07-30
2016-05-27
我的也是這樣的,代碼改了一遍,還是沒(méi)用,求大神指點(diǎn)
2016-05-16
代碼敲錯(cuò)了
2016-05-15
import re
import urlparse
from bs4 import BeautifulSoup
class HtmlParser(object):
? ? def _get_new_urls(self,page_url,soup):
? ? ? ? new_urls=set()
? ? ? ? links=soup.find_all('a',href=re.compile(r"/view/\d+\.htm"))
? ? ? ? for link in links:
? ? ? ? ? ? new_url=link['href']
? ? ? ? ? ? new_full_url=urlparse.urljoin(page_url,new_url)
? ? ? ? ? ? new_urls.add(new_full_url)
? ? ? ? return new_urls
? ? def _get_new_data(self,page_url,soup):
? ? ? ? res_data={}
? ? ? ? #url
? ? ? ? res_data['url']=page_url
? ? ? ??
? ? ? ? #<dd class="lemmaWgt-lemmaTitle-title"><h1>Python</h1>
? ? ? ? title_node=soup.find('dd',class_="lemmaWgt-lemmaTitle-title")
? ? ? ? res_data['title']=title_node.get_text()
? ? ? ? #<div class="lemma-summary" >
? ? ? ? summary_node=soup.find('div',class_="lemma-summary")
? ? ? ? res_data['summary']=title_summary.get_text()
? ? ? ? return res_data
? ? def parse(self,page_url,html_cont):
? ? ? ? if page_url is None or Html_cont is None:
? ? ? ? ? ? return
? ? ? ? soup=BeautifulSoup(html_cont,'html.parser',from_encoding='utf-8')
? ? ? ? new_urls=self._get_new_urls(page_url,soup)
? ? ? ? new_data=self._get_new_data(page_url,soup)
? ? ? ? return new_urls,new_data
? ? ? ??
代碼就是按照視頻敲的,不知道哪錯(cuò)了
2016-05-15
我也是這樣的
2016-05-15
我之前也是這樣的 ?不過(guò)現(xiàn)在解決了 應(yīng)該是html_parser.py 有問(wèn)題,找找代碼是不是有錯(cuò)誤,或者你把代碼貼上來(lái) ,我?guī)湍阏艺??,我也是早上剛找到的錯(cuò)誤
2016-05-14
我也是這樣的 ?請(qǐng)問(wèn)你解決了嗎?