python抓取百度首页的方法

yipeiwu_com6年前Python爬虫

本文实例讲述了python抓取百度首页的方法。分享给大家供大家参考。具体实现方法如下:

import urllib
def downURL(url,filename):
  try:
    fp=urllib.urlopen(url)
  except:
    print('download error')
    return 0
  op=open(filename,'wb')
  while 1:
     s=fp.read()
     if not s:
       break
     op.write(s)
  fp.close()
  op.close()
  return 1
downURL("http://www.baidu.com","C:\\url.txt")

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python实现多线程抓取网页功能实例详解

本文实例讲述了Python实现多线程抓取网页功能。分享给大家供大家参考,具体如下: 最近,一直在做网络爬虫相关的东西。 看了一下开源C++写的larbin爬虫,仔细阅读了里面的设计思想和...

Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】

Python3爬虫爬取英雄联盟高清桌面壁纸功能示例【基于Scrapy框架】

本文实例讲述了Python3爬虫爬取英雄联盟高清桌面壁纸功能。分享给大家供大家参考,具体如下: 使用Scrapy爬虫抓取英雄联盟高清桌面壁纸 源码地址:https://github.co...

python爬取网易云音乐评论

本文实例为大家分享了python爬取网易云音乐评论的具体代码,供大家参考,具体内容如下 import requests import bs4 import json def g...

python用BeautifulSoup库简单爬虫实例分析

会用到的功能的简单介绍 1、from bs4 import BeautifulSoup #导入库 2、请求头herders headers={'User-Agent': 'Mo...

python制作最美应用的爬虫

安卓最美应用页面爬虫,爬虫很简单,设计的东西到挺多的 文件操作 正则表达式 字符串替换等等 import requests import re url = "http://zuime...