python抓取百度首页的方法

yipeiwu_com7年前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多线程抓取天涯帖子内容示例

使用re, urllib, threading 多线程抓取天涯帖子内容,设置url为需抓取的天涯帖子的第一页,设置file_name为下载后的文件名 复制代码 代码如下:#coding:...

python支持多线程的爬虫实例

python是支持多线程的, 主要是通过thread和threading这两个模块来实现的,本文主要给大家分享python实现多线程网页爬虫 一般来说,使用线程有两种模式, 一种是创建线...

requests和lxml实现爬虫的方法

如下所示: # requests模块来请求页面 # lxml模块的html构建selector选择器(格式化响应response) # from lxml import html # i...

python3.7简单的爬虫实例详解

python3.7简单的爬虫,具体代码如下所示: #https://www.runoob.com/w3cnote/python-spider-intro.html #Python...

python 爬虫百度地图的信息界面的实现方法

python 爬虫百度地图的信息界面的实现方法

在爬虫百度地图的期间,就为它做了一个界面,运用的是PyQt5。 得到意想不到的结果: # -*- coding: utf-8 -*- # Form implementation...