2 lb3690 LB3690 于 2017.08.31 15:56 提问

初学python 简单urllib问题

-*- 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   Ds   Rxr 2017.08.31 16:32
已采纳

URL格式注意

 url='http://www.dbmeinv.com/?pager_offset=1'
LB3690
LB3690 感激!多谢!内牛满面!
3 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片