我想使用urllib2刮一個網站。但是,我得到一個400頁面未找到錯誤。這裏是我的代碼:404錯誤urllib2.urlopen()
rec_text = 'Genesis 1:1'
my_text = rec_text.strip()
book = my_text.split()[0]
chapter_verse = my_text.split()[1]
chapter = chapter_verse.split(':')[0]
verse = chapter_verse.split(':')[1]
webpage = urllib2.urlopen('http://bible.cc/'+book+'/'+chapter+'-'+verse+'.htm').read()
stuffToSearch = ""
for line in webpage:
stuffToSearch += line
search_for = re.compile(r'<a href="http://kingjbible.com/'+book+'/'+chapter+'.htm">King James Bible</a></span><br>(.*)<p><span class="versiontext"><a href="http://kjv.us/'+book+'/'+chapter+'.htm">')
search_it = re.search(search_for, stuffToSearch)
print(search_it.group(1))
確保您嘗試「urlopen」的URI指向可用資源。 –