[Python] Python crawl source code examples to share the page

This article is about the use of Python method to capture a website to share an example of a method of source page. I need to note that the source code examples Python crawled share pages, is to be imported after BeautifulSoup.py file at run time can be used.

Python fetch page sharing source code examples, python urllib2 need to use a modular approach and BeautifulSoup module.

Source as follows:


#coding:utf-8
import urllib2
from BeautifulSoup import BeautifulSoup

'''
www.iplaypy.com
'''
#define
def readPage(Url):
    page = urllib2.urlopen(Url).read()
    pageContent = BeautifulSoup(page)
    OSC_Content = pageContent.find("div",{'id':'OSC_Content'})
    preHandleCode = OSC_Content.find('pre').next
    print preHandleCode

'''
页面的url需指定
''' 
#call  
readPage('http://www.xxxxxx.net/code/snippet_580365_11857')

python资源分享扣扣群:855408893 ,与你分享Python企业当下人才需求,怎么学Python,和学习什么内容!

The goal here has been to hide the site, we can stand on their own for the target to be captured, this python reference source with appropriate modifications.

Guess you like

Origin blog.51cto.com/14429370/2417278
Recommended