代码如下:
import urllib
import urllib2
import re
url ='http://www.yingjiesheng.com/guangzhou-moreptjob-2.html'
req = urllib2.Request(url)
try:
html = urllib2.urlopen(req).read()
print html
except urllib2.HTTPError, e:
print 'The server couldn\'t fulfill the request.'
print 'Error code: ', e.code
except urllib2.URLError, e:
print 'We failed to reach a server.'
print 'Reason: ', e.reason
else:
print 'No exception was raised.'
求:在爬取网页源代码的时候返回空的原因及解决方案(或解决方向)~求大神指点迷津啊!
(PS:在处理这个问题的时候,我曾在IDLE上直接敲这段代码运行,有时候可以返回源代码有时候不可以,另外,有时候我把程序运行了几十遍之后,就能返回源代码,这时候我把url的数字2改为3时(即相当下一页),又不可以了,好诡异~~)