![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据采集
sunshinegaigai
写点笔记给以后的自己看。。。
展开
-
Python之数据采集(No.1)
1.初建python文件时,会默认生成下面文件 –init–文件的作用是构造函数或者初始化程序 2.urlib是Python的标准库,包含从网络请求数据,处理cookie,改变像请求头,用户代理这些元数据的函数,同时它也可以用来打开并读取一个从网络获取的远程对象 3.BeautifulSoup库中最常用的就是BeautifulSoup对象(html后面的read方法可有可无) from urll...原创 2019-05-09 18:01:54 · 401 阅读 · 0 评论 -
Python之数据采集(No.2)
1原创 2019-05-10 15:28:21 · 129 阅读 · 0 评论 -
select 方法
关于beautifulsoup---html解析库方法的使用参考一个大神的笔记(https://blog.csdn.net/qq_21933615/article/details/81171951) 首先让我们先了解一下user-agent(地址栏里直接输入about://version即可) 通过user-agent不能完全准确的判断是属于那款浏览器。由于UA字符串在每次浏览器HTTP 请求...原创 2019-05-28 07:50:34 · 1386 阅读 · 0 评论 -
正则表达式的运用
re模块(集中了正则表达式所有的功能) ¨邮箱地址 [A~Za~z0-9\._+]+@[A~Za~z]+\.(com|edu|net) 其中[A~Za~z0-9\._+]+表示一个字符要满足中括号里的范围,字符可以是A~Z或者a~z或者0-9或者“."(¨元字符包括:. * ? + ^ $ | \,所以需要匹配元字符时需要加上反斜线\ ),可以出现1到n次 接着加上“@”字符 [A~Z...原创 2019-06-15 11:24:51 · 232 阅读 · 0 评论 -
爬取一个网站
如果一个页面有10个链接,网站上有5个页面深度(中等规模网站的主流深度),如果要采集整个网站,一共需要采集的网页数量就是10^5,即100000个页面,因为很少有网站会涉及到这么多的网页,因为有很大一部分是因为网页重复的原因,为了避免采集两次,链接去重很重要 from urllib.request import urlopen from bs4 import BeautifulSoup imp...原创 2019-06-16 20:36:10 · 9847 阅读 · 0 评论 -
网页解析库--lxml
from bs4 import BeautifulSoup from lxml import etree doc='''<html> <body> <title> A story </title> <p class="title"> <b> Story begin! </b&g...原创 2019-06-17 14:22:07 · 760 阅读 · 0 评论 -
python与mysql
链接,插入数据 import pymysql conn=pymysql.connect(host='localhost',user='root',passwd='root',db='mydb',port=3306,charset='utf8') cursor=conn.cursor() cursor.execute("insert into students(name,sex,grade) V...原创 2019-06-17 17:09:45 · 301 阅读 · 0 评论 -
作业整理
1. from urllib.request import urlopen from bs4 import BeautifulSoup import pymysql conn=pymysql.connect(host='localhost',user='root',passwd='root',db='mydb',port=3306,charset='utf8') cursor=conn.cu...原创 2019-06-27 10:14:28 · 274 阅读 · 0 评论