【Python】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资源分享扣扣群:855408893 ,与你分享Python企业当下人才需求,怎么学Python,和学习什么内容!

这里的目标网站已经隐藏,大家可针对自己要抓取的目标站,参考本python源码适当修改。

原文地址:https://blog.51cto.com/14429370/2417278

时间: 2024-08-07 22:07:56

【Python】Python抓取分享页面的源代码示例的相关文章

使用python+phantomjs抓取动态页面

前一段时间公司需要爬取部分web页面的数据使用.但是页面中的主要数据是ajax load出来的,传统的抓取方法是拿不到数据的.后来在网上发现了phantomjs,在无界面的情况下运行js,渲染dom.用这个工具抓取ajax load出来的数据再方便不过啦. 系统环境:CentOS release 6.5 (Final) phantomjs版本:1.9.8 phantomjs抓取加载完整的dom结构.说到phantomjs怎么把数据传递给处理程序,我看到网上很多人是写一个本地文件,然后具体的处理程

Python爬虫--抓取单一页面上的图片文件学习

#!/usr/bin/python import sys #正则表达式库 import re import urllib def getHtml(url):     page = urllib.urlopen(url)     html = page.read()     return html      def getImg(html):     reg = r'src="(.=?\.jpg)"'     imgre = re.compile(reg)     imglist = r

python 爬虫抓取心得分享

/** author: insun title:python 爬虫抓取心得分享 blog:http://yxmhero1989.blog.163.com/blog/static/112157956201311821444664/ **/    0x1.urllib.quote('要编码的字符串') 如果你要在url请求里面放入中文,对相应的中文进行编码的话,可以用: urllib.quote('要编码的字符串') query = urllib.quote(singername) url = 'h

python 爬虫抓取心得

quanwei9958 转自 python 爬虫抓取心得分享 urllib.quote('要编码的字符串') 如果你要在url请求里面放入中文,对相应的中文进行编码的话,可以用: urllib.quote('要编码的字符串') query = urllib.quote(singername) url = 'http://music.baidu.com/search?key='+query response = urllib.urlopen(url) text = response.read()

python爬虫抓取哈尔滨天气信息

python 爬虫 爬取哈尔滨天气信息 - http://www.weather.com.cn/weather/101050101.shtml 环境: windows7 python3.4(pip install requests:pip install BeautifulSoup4) 代码:(亲测可以正确执行) 1 # coding:utf-8 2 """ 3 总结一下,从网页上抓取内容大致分3步: 4 1.模拟浏览器访问,获取html源代码 5 2.通过正则匹配,获取指定

python Web抓取(一)

需要的模块: python web抓取通过: webbrowser:是python自带的,打开浏览器获取指定页面 requests:从因特网上下载文件和网页 Beautiful Soup:解析HTML Selenium:启动并控制一个Web浏览器.selenium能够填写表单,并模拟鼠标在这个浏览器中点击   >>>这个在这里 一.项目:利用Webbrowser模块的快速翻译脚本  webbrowser.open(url) 会在默认浏览器中打开这个地址 >>> impo

Python爬虫抓取网页图片

本文通过python 来实现这样一个简单的爬虫功能,把我们想要的图片爬取到本地. 下面就看看如何使用python来实现这样一个功能. # -*- coding: utf-8 -*- import urllib import re import time import os #显示下载进度 def schedule(a,b,c): ''''' a:已经下载的数据块 b:数据块的大小 c:远程文件的大小 ''' per = 100.0 * a * b / c if per > 100 : per =

一个极其简洁的Python网页抓取程序

paip. 混合编程的实现resin4 (自带Quercus ) 配置 php 环境 #---混合编程的类型 1.代码inline 方式 2.使用库/api  解析方式. #----配置resin 支持php resin4默认自动支持php.. 也能手动配置了.web.xml加php的servlet解析..参考Quercus让你的PHP开心在Servlet容器奔跑 #----配置 php.ini路线 运行t.php,,看见 Configuration File (php.ini) Path =>

python爬虫抓取站长之家IP库,仅供练习用!

python爬虫抓取站长之家IP库,单线程的,仅供练习,IP库数据有43亿条,如果按此种方法抓取至少得数年,所以谨以此作为练手,新手代码很糙,请大家见谅. #!/usr/bin/python #coding=UTF-8 import urllib2 import re import os import csv import codecs user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)' headers = { 'User-