haibaraxx的个人博客分享 http://blog.sciencenet.cn/u/haibaraxx

博文

Python 2: open a webpage

已有 1989 次阅读 2016-3-8 04:08 |个人分类:Python|系统分类:科研笔记| Open, Webpage

import urllib2     # the urllib2 module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world - basic and digest authentication, redirections, cookies and more.

url1 = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'
response1 = urllib2.urlopen(url1)      # call the function urlopen which is stored in the urllib2 module to open the specified URL. Then save the open version of the requested webpage into the variable response1.
webContent1 = response1.read()      # copy the contents of the requested open webpage into the vatiable webContent1.

f = open('obo_webpage','w')
f.write(webContent1)
f.close
print webContent1 [0:300]      # index the first 300 rows.

url2 = 'http://dict.youdao.com/search?le=eng&q=redirection&keyfrom=dict.top'
response2 = urllib2.urlopen (url2)
webContent2 = response2.read ()

print webContent2



https://blog.sciencenet.cn/blog-3031432-961141.html

上一篇:Python 2: read and write from a file
下一篇:Matlab: operations for matrix
收藏 IP: 134.1.1.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-7-17 23:14

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部