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 爬虫一键爬取 淘宝天猫宝贝页面主图颜色图和详情图的教程

实例如下所示: import requests import re,sys,os import json import threading import pprint class s...

Python爬虫天气预报实例详解(小白入门)

Python爬虫天气预报实例详解(小白入门)

本文研究的主要是Python爬虫天气预报的相关内容,具体介绍如下。 这次要爬的站点是这个:http://www.weather.com.cn/forecast/ 要求是把你所在城市过去...

一些常用的Python爬虫技巧汇总

Python爬虫:一些常用的爬虫技巧总结 爬虫在开发过程中也有很多复用的过程,这里总结一下,以后也能省些事情。 1、基本抓取网页 get方法 import urllib2 url...

python网络爬虫采集联想词示例

python爬虫_采集联想词代码 复制代码 代码如下:#coding:utf-8import urllib2import urllibimport reimport timefrom r...

scrapy spider的几种爬取方式实例代码

本节课介绍了scrapy的爬虫框架,重点说了scrapy组件spider。 spider的几种爬取方式: 爬取1页内容 按照给定列表拼出链接爬取多页 找到‘下一页'标签进行...