공유 페이지의 Python 캡처 소스 코드 예

이 기사는 Python 메소드를 사용하여 웹사이트의 공유 페이지에서 소스 코드 메소드를 가져오는 방법에 관한 것입니다. 모두가 주의해야 할 점은 공유 페이지를 크롤링하는 Python의 소스 코드 예제는 런타임에 BeautifulSoup.py 파일을 가져온 후에만 사용할 수 있다는 것입니다.

Python은 공유 페이지의 소스 코드 예제를 캡처하며 Python urllib2 모듈 메서드 와 BeautifulSoup 모듈을 사용해야 합니다 .

소스 코드는 다음과 같습니다.


#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 소스 코드를 참조하여 크롤링하려는 대상 웹사이트를 적절하게 수정할 수 있습니다.

おすすめ

転載: blog.csdn.net/lmrylll/article/details/131961852