
爬虫-pyhon
采蘑菇的老姑娘
这个作者很懒,什么都没留下…
展开
-
python爬虫HTTP请求头修改和异常处理方法,设置中文HTTP请求头
一.简单的获取网页''' 简单的获取网页'''import urllib.requestresponse = urllib.request.urlopen('https://baidu.com')print(response.read().decode('utf-8'))print(type(response))二.通过HTTPRreponse获取对象中主要的方法和属性的用法'''获取HTTPResponse中主要的方法和属性'''import urllib.requestres原创 2020-12-09 23:35:53 · 1597 阅读 · 0 评论 -
python实现访问需要登陆的网页
一 首先使用flask 编写一个Web服务器,用于模拟基础验证页面。代码如下。from flask import Flaskfrom flask import requestimport base64app = Flask(__name__)def hasAuth(auth,response): if auth == None or auth.strip() == "": response.status_code = 401 response.heade原创 2020-09-06 15:54:08 · 1853 阅读 · 0 评论 -
python3 爬虫urllib中http get,post,超时,设置中文请求头的使用方法例子
一.http get练习:import urllib.requestresponse = urllib.request.urlopen('https://baidu.com')print(response.read().decode('utf-8'))print(type(response))import urllib.requestreponse = urllib.request.urlopen('https://jd.com')print('response类型:', type(r原创 2020-08-29 17:31:53 · 1161 阅读 · 0 评论 -
python3爬虫:利用正则抓取博客文章列表和地址
题目:抓取博客https://www.cnblogs.com/ 里的文章标题和url地址。并将标题和url输出的console。代码如下图,思路和注释也在图中:#!usr/bin/env python3#-*-coding=utf-8-*-__author__='km'import urllib.requestfrom re import *import redef download(url): result = urllib.request.urlopen(url=url)原创 2020-08-29 16:40:13 · 289 阅读 · 0 评论 -
python爬虫-第一个爬虫
1.本地安装了nginx, 在默认的html目录下建立测试html代码:2.修改nignx配置使得本地可以访问写的kmtest里的index.html。参考文档https://www.cnblogs.com/erlou96/p/12091067.htmlnginx默认访问html目录下的index,我在html下新创建了kmtest,然后kmtest里创建了测试用的index.html。修改完conf下的nginx.conf完之后,记得重启nginx生效。3.然后访问本地http:/原创 2020-07-13 22:15:08 · 177 阅读 · 0 评论