CS109 Lecture 7
2016-07-29 17:07
134 查看
CS109 Lecture 7
Data Scraping
Sources
From a Web SitesWith An API
Copyrights and permission
Be careful and politeGive credit
Care about media law
Don’t be evil
Useful tags
<h1></h1> <p></p> <br> <a href = 'url'>Link</a>
Useful Libraries for Scraping
urllibbeautifulsoup
pattern
LXML
Get Data From Website
url = 'url' scource = urllib2.urlopen(url).read()
soup = bs4.BeautifulSoup(source) soup.findAll('a') # find <a><\a> tag
tag = soup.find('a') tag.get('href')
C = soup.findAll('p',{'class':'Event'}) t=C[0] t.findNextSiblings
Get Data With An API
import json # JavaScript Obejct Notation import requests api_key = 'mykey' url = 'url' + api_key scource = urllib2.urlopen(url).read()
#---simple example-------- a = {'a':1,'b':2} s = json.dump(a) a2 = json.loads(s) #------------------------- dataDict = json.loads(data) dtatDict.keys()
相关文章推荐
- 数据可视化中需要注意的问题
- CS109 Lecture 2
- CS109 Lecture 3
- CS109 Lecture 4
- CS109 Lecture 5
- 【BZOJ-2299】向量 裴蜀定理 + 最大公约数
- linux命令:find详解
- mac nginx + php 开发环境集成
- Android触摸事件总结
- todo
- Uoj 33 树上GCD (树分治)
- Java:万年历打印输出
- python __set__ __get__ 等解释
- 趣味100道C语言编程题num ten
- 链表的增删改查(带头节点)
- 删除github上的仓库
- SpringMVC 整合拦截器
- Linux-字符编码转换学习
- Java封装学习
- Github:每次git push推送的时候都需要输入git的用户名和密码