URL のファイルを読み取る Python スクリプトを作成していますが、すべてが機能するとは限りません。以下に投稿したエラーを発生させるのではなく、これを回避してファイルの次の行を読み取る方法を見つけようとしています。ある種の if ステートメントが必要なのはわかっていますが、よくわかりません。
from mechanize import Browser
from BeautifulSoup import BeautifulSoup
import csv
me = open('C:\Python27\myfile.csv')
reader = csv.reader(me)
mech = Browser()
for url in me:
response = mech.open(url)
html = page.read()
soup = BeautifulSoup(html)
table = soup.find("table", border=3)
for row in table.findAll('tr')[2:]:
col = row.findAll('td')
BusinessName = col[0].string
Phone = col[1].string
Address = col[2].string
City = col[3].string
State = col[4].string
Zip = col[5].string
Restaurantinfo = (BusinessName, Phone, Address, City, State)
print "|".join(Restaurantinfo)
そのコード ブロックを実行すると、次のエラーが発生します。
httperror_seek_wrapper: HTTP エラー 404: 見つかりません
基本的に私が求めているのは、Python がそれを無視して次の URL を試す方法です。