当我想在 Debian 9.1 上运行 python 脚本时,我收到此错误消息。我正在使用 MariaDB 10.1。
这里有什么问题?我该如何修复它?
我的相关sql代码在这里:
connection = MySQLdb.connect(host='localhost',
user='root',
passwd='1234',
db='database')
cursor = connection.cursor()
query = """ load data local infile 'MYOUTPUTLOCATION'
into table DEPARTURES
character set latin1
fields terminated by ';'
enclosed by '"'
lines terminated by '\r\n'
ignore 1 lines;
"""
cursor.execute(query)
connection.commit()
cursor.close()
Run Code Online (Sandbox Code Playgroud) 我有一个网页抓取脚本,它正在处理数千个链接。但有时我会收到连接错误、超时错误、网关错误错误,而我的脚本只是停止..
这是我的部分代码(在 url 中,我得到了我循环运行的链接):
def scrape(urls):
browser = webdriver.Firefox()
datatable=[]
for url in urls:
browser.get(url)
html = browser.page_source
soup=BeautifulSoup(html,"html.parser")
table = soup.find('table', { "class" : "table table-condensed table-hover data-table m-n-t-15" })
Run Code Online (Sandbox Code Playgroud)
我想我必须使用 try-catch 方法来避免它,如果它发生了,请再试一次阅读这个网站。
我的问题是我必须在我的代码中构建的位置和内容,以捕获这些错误并重试/转到下一个链接?
try:
r = requests.get(url, params={'s': thing})
except requests.exceptions.RequestException:
# what i have to write plus and where i have to place correctly this part?
Run Code Online (Sandbox Code Playgroud)
谢谢!
debian ×2
python ×2
browser ×1
linux ×1
mariadb ×1
mysql-python ×1
try-catch ×1
web-scraping ×1