python爬虫入门urllib库的使用

urllib库的使用

python爬虫入门urllib库的使用

只要几句代码就可以把一个网站的源代码下载下来。

python爬虫入门urllib库的使用

也可以这样使用:

python爬虫入门urllib库的使用

这种用法比较常见。

 我们用php创建一个表单,然后用urllib2模拟表单提交

python爬虫入门urllib库的使用

接下来,我们先用get方式提交【备注:域名是我本地的,你需要用本地host映射,相应的服务器域名和ip】

python爬虫入门urllib库的使用

执行之后,如果把用户名或者密码该错,就会出现login error.

python爬虫入门urllib库的使用

post提交方式,当然你要把php表单改成post提交.python爬虫入门urllib库的使用