##安装## `sudo pip install pyquery` ##例子## ``` from pyquery import PyQuery import urllib2 page = urllib2.urlopen("http://www.lzu.edu.cn") text = unicode(page.read(), "utf-8") doc = PyQuery(text) ...
分类:
Web程序 时间:
2015-03-07 14:21:17
阅读次数:
470
一、安装Package Control
按照提示复制一段python命令安装Package Control,也可以直接复制这一段到控制台(Ctrl+~)
import urllib2,os; pf='Package Control.sublime-package'; ipp=sublime.installed_packages_path(); os.makedirs(ipp) if n...
分类:
系统相关 时间:
2015-03-05 17:06:09
阅读次数:
182
python urllib2模块urlopen()最常用的函数
urllib2.urlopen(url[, data[, timeout[, cafile[, capath[, cadefault[, context]]]]])
Open the URL url, which can be either a string or a Request object.
他有几个参数比较重要的...
分类:
编程语言 时间:
2015-03-04 13:01:22
阅读次数:
180
主要就是用了两个库,urllib和BeautifulSoup.作用是从HTML中解析出解梦的查询词和具体的解释。 1 # -*- coding: utf-8 -*- 2 import urllib, urllib2 3 import time, random 4 from BeautifulSoup...
分类:
编程语言 时间:
2015-03-01 14:23:32
阅读次数:
189
使用Python的urllib读取网页,报错:[Errno 11004] getaddrinfo failed主要原因是需要在Python中设置proxy加入下面语句即可解决这个问题proxy_support = urllib2.ProxyHandler({"http":"http://proxy....
分类:
其他好文 时间:
2015-02-27 16:57:33
阅读次数:
264
#---------------------------------import---------------------------------------
#coding:utf-8
import urllib2;
from BeautifulSoup import BeautifulSoup;
#-----------------------------------------------...
分类:
编程语言 时间:
2015-02-21 09:46:47
阅读次数:
256
1 #!/usr/bin/env python 2 #-*- coding: utf-8 -*- 3 'a translate module ' 4 import sys 5 import urllib2 6 import json 7 def translate(word): 8 url="...
分类:
编程语言 时间:
2015-02-17 18:46:30
阅读次数:
183
网页内容的解析可以说是爬虫最主要和最核心的工作,从一堆看似杂乱的代码中获取我们需要的信息,这就是爬虫的本质。python对于网页解析提供了很多的方式,传统的即通过urllib2包获取网页代码,再通过re正则表达式模块自己写规则来获取信息。第三方的包也有,类似pyquery、lxml、Beautifu...
分类:
其他好文 时间:
2015-02-15 18:03:18
阅读次数:
270
# -*- coding=utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup as bs3
import json
import codecs
#字符检测,用来检测其真实的编码格式
import chardet
#save content to file
def save_to_file(filename, co...
分类:
Web程序 时间:
2015-02-14 23:51:34
阅读次数:
333
以汽车之家为例子,抓取页面并进行解析
# -*- coding=utf-8 -*-
import urllib2
from BeautifulSoup import BeautifulSoup as bs3
import json
import codecs
#字符检测,用来检测其真实的编码格式
import chardet
#save content to file
def save_...
分类:
其他好文 时间:
2015-02-14 17:35:13
阅读次数:
178