當前位置: 首頁>>代碼示例>>Python>>正文


Python Crawler.get_page方法代碼示例

本文整理匯總了Python中Crawler.Crawler.get_page方法的典型用法代碼示例。如果您正苦於以下問題:Python Crawler.get_page方法的具體用法?Python Crawler.get_page怎麽用?Python Crawler.get_page使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Crawler.Crawler的用法示例。


在下文中一共展示了Crawler.get_page方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_article

# 需要導入模塊: from Crawler import Crawler [as 別名]
# 或者: from Crawler.Crawler import get_page [as 別名]
    def get_article(self, url):
        crawler = Crawler()
        # get html data from url
        web_data = crawler.get_page(url)
        soup = BeautifulSoup(web_data, 'html.parser')

        # remove link news 
        [e.extract() for e in soup('div', {'class':'link_news'})]

        # article title
        self.title = soup('h3', {'id':'articleTitle'})[0].text

        # create date and time of article
        date_time = soup('span', {'class':'t11'})[0].text.split()
        self.date = date_time[0]
        self.time = date_time[1]

        # press name
        press_logo = soup('div', {'class':'press_logo'})[0]
        self.press = press_logo.find('img')['alt']
        del press_logo

        # article contents
        self.contents = soup('div', {'id':'articleBodyContents'})[0].text
        self.contents = re.sub('[\n\r]', '', self.contents)
開發者ID:ByeongkiJeong,項目名稱:naverNewsCrawler,代碼行數:27,代碼來源:navernews.py

示例2: get_list

# 需要導入模塊: from Crawler import Crawler [as 別名]
# 或者: from Crawler.Crawler import get_page [as 別名]
def get_list(section, date):

    # NAVER news url
    naver_news_url = 'http://news.naver.com/main/list.nhn'
    naver_news_parameter = {'mode':'LSD', 'mid':'sec', 'sid1':'', 'date':date, 'page':''}
    naver_news_parameter['sid1'] = section

    page = 1
    url_list = []
    while True:
        naver_news_parameter['page'] = page
        url =  naver_news_url + '?' + urllib.urlencode(naver_news_parameter)
        
        # get html data
        crawler = Crawler()
        web_data = crawler.get_page(url)
        
        # html parsing
        soup= BeautifulSoup(web_data, 'html.parser')
        list_body = soup('div', {'class':'list_body newsflash_body'})[0]

        # get each article's url
        list_body = list_body.findAll('li')
        current_list = []
        for e in list_body:
            current_list.append(e.find('a')['href'])
        del list_body
        
        # break when current page is end of url list
        if current_list[0] in url_list:
            break

        # add to url list
        url_list += current_list

        # next url page
        page += 1

    return url_list
開發者ID:ByeongkiJeong,項目名稱:naverNewsCrawler,代碼行數:41,代碼來源:navernews.py


注:本文中的Crawler.Crawler.get_page方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。