LB3690
LB3690
采纳率100%
2017-08-31 07:56 阅读 1.2k

初学python 简单urllib问题

10

-*- coding: utf-8 -*-

import urllib
import urllib2
url='www.dbmeinv.com/?pager_offset=1'
def crawl(url):#
hds ={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; W…) Gecko/20100101 Firefox/55.0'}
req=urllib2.Request(url,headers=hds)
page=urllib2.urlopen(req,timeout=20)
contents=page.read()
print contents
crawl(url)
###################################下面是报错信息
Traceback (most recent call last):
File "C:/Temp/pa-chong/del.py", line 11, in
crawl(url)
File "C:/Temp/pa-chong/del.py", line 8, in crawl
page=urllib2.urlopen(req,timeout=20)
File "C:\Python27\lib\urllib2.py", line 154, in urlopen
return opener.open(url, data, timeout)
File "C:\Python27\lib\urllib2.py", line 421, in open
protocol = req.get_type()
File "C:\Python27\lib\urllib2.py", line 283, in get_type
raise ValueError, "unknown url type: %s" % self.__original
ValueError: unknown url type: www.dbmeinv.com/?pager_offset=1

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    oyljerry oyljerry 2017-08-31 08:32

    URL格式注意

     url='http://www.dbmeinv.com/?pager_offset=1'
    
    点赞 评论 复制链接分享

相关推荐