# _*_ coding:utf-8 _*_

import urllib2
import cookielib
import random
import re
from bs4 import BeautifulSoup
import datetime

dax = datetime.datetime.now().strftime('%Y-%m-%d')
print(dax)

url = 'http://ww=singlemessage&isappinstalled=0'

cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
request = urllib2.Request(url)
headers = [
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; 360SE)',
'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon 2.0)',
'Opera/9.80 (Windows NT 6.1; U; en) Presto/2.8.131 Version/11.11',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0',
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_8; en-us) AppleWebKit/534.50 (KHTML, like Gecko) Version/5.1 Safari/534.50'
]

hds = random.choice(headers)
# print(hds)
request.add_header('User-Agent','%s' % hds)
#response = urllib2.urlopen("http://www.hn1m=singlemessage&isappinstalled=0")
response = urllib2.urlopen(request)
cont = response.read()
#print(cont)

soup = BeautifulSoup(cont,'html.parser',from_encoding='utf-8')
# print(soup)
# listyj = soup.find_all('dl')
# for listyjx in listyj:
# print(listyjx.name,listyjx.attrs,listyjx.gettext())
# # if dax in listyjx:
# # print(listyjx)

python2.7 urllib2 爬虫的更多相关文章

  1. python2下经典爬虫(第一卷)

    python2.7的爬虫个人认为比较经典在此我将会用书中的网站http://example.webscraping.com作为案例 爬虫第一步:进行背景调研 了解网站的结构资源在网站的robots.t ...

  2. Python2和Python3 爬虫 转换

    由于Python3的不断完善,很多新入Python的小伙伴选择了Python3的阵营,很多人选择了爬虫这一热门话题,但是网络上大部分教程都是Python2 教程,Python3这一块做了些许的改动,对 ...

  3. 关于urllib、urllib2爬虫伪装的总结

    站在网站管理的角度,如果在同一时间段,大家全部利用爬虫程序对自己的网站进行爬取操作,那么这网站服务器能不能承受这种负荷?肯定不能啊,如果严重超负荷则会时服务器宕机(死机)的,对于一些商业型的网站,宕机 ...

  4. [Selenium2+python2.7][Scrap]爬虫和selenium方式下拉滚动条获取简书作者目录并且生成Markdown格式目录

    预计阅读时间: 15分钟 环境: win7 + Selenium2.53.6+python2.7 +Firefox 45.2  (具体配置参考 http://www.cnblogs.com/yoyok ...

  5. python2与python3爬虫中get与post对比

    python2中的urllib2改为python3中的urllib.request 四种方式对比: python2的get: # coding=utf-8 import urllib import u ...

  6. python2.x urllib2和urllib的使用

    1.最简单用法 urlopen(url, data=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,...) import urllib2 import ur ...

  7. Python2 基于urllib2 的HTTP请求类

    一个利用urllib2模块编写的下载器,虽然有了requests模块,但是毕竟标准库 import urllib2,random class strong_down(): def __init__(s ...

  8. python2中urllib2模块带cookies使用方法

    #!/usr/bin/python # coding=utf-8 #############方式1######################### import urllib2 cookie = & ...

  9. python3--网络爬虫--爬取图片

    网上大多爬虫仍旧是python2的urllib2写的,不过,坚持用python3(3.5以上版本可以使用异步I/O) 相信有不少人爬虫第一次爬的是Mm图,网上很多爬虫的视频教程也是爬mm图,看了某人的 ...

随机推荐

  1. 【java】Hello World

    class Demo { //程序的主入口,能保证类的独立运行 public static void main(String[] args) { System.out.println("He ...

  2. jQuery实现点赞动态效果

    实现动态效果基本上都是用到定时器,修改标签的位置大小颜色属性 <!DOCTYPE html> <html lang="en"> <head> & ...

  3. 用DLL实现插件的简单演示

    这是DLL的代码 library MyDll; uses SysUtils, Dialogs, Classes; procedure ShowInfo(info:PChar);stdcall; beg ...

  4. 关于class produre

    很好理解 type TMessageHandler = class //使得回车消息转换成Tab消息 class procedure AppMessage(var Msg:TMsg;var Handl ...

  5. Python 简说 list,tuple,dict,set

    python 是按缩进来识别代码块的 . 缩进请严格按照Python的习惯写法:4个空格,不要使用Tab,更不要混合Tab和空格,否则很容易造成因为缩进引起的语法错误. list  有序集合  访问不 ...

  6. C/C++基础----随机数分布和随机数引擎

    随机数分布 除了伯努利分布,其他都是模板,接收单个类型参数,指出分布生成的结果类型. 表示分布生成浮点数,float.double或long double 表示要求一个整型类型,不包括bool或任何c ...

  7. 【深度学习】BP反向传播算法Python简单实现

    转载:火烫火烫的 个人觉得BP反向传播是深度学习的一个基础,所以很有必要把反向传播算法好好学一下 得益于一步一步弄懂反向传播的例子这篇文章,给出一个例子来说明反向传播 不过是英文的,如果你感觉不好阅读 ...

  8. 面试总结之PYTHON

    source code https://github.com/haoran119/interview/tree/master/interview%20summary%20of%20python [ZZ ...

  9. mysql 意向锁的作用

    直接copy知乎上的内容 https://www.zhihu.com/question/51513268 作者:尹发条地精链接:https://www.zhihu.com/question/51513 ...

  10. idea 破解方法--可以使用到2099年

    破解方式有2种,第一种比较方便 第一种比较方便 1.使用注册码破解:http://idea.lanyus.com/ 复制这段: 2. 修改hosts文件: hosts位置:C:\Windows\Sys ...