我在python程序中遇到连接错误
你试过运行我的程序,但每次运行到一半我都会出错 基本上,我的程序是这样做的: 1.从我的网站获取xml 2.运行所有的URL 3.从我的网页获取数据(sku、名称、标题、价格等) 4.通过使用相同的sku压缩价格,从其他网站获得最低价格 问题是我的xml中有7000多个URL,所以我的程序每次都会出错 怎么办?我如何解决它我在python程序中遇到连接错误,python,python-3.x,networking,error-handling,Python,Python 3.x,Networking,Error Handling,你试过运行我的程序,但每次运行到一半我都会出错 基本上,我的程序是这样做的: 1.从我的网站获取xml 2.运行所有的URL 3.从我的网页获取数据(sku、名称、标题、价格等) 4.通过使用相同的sku压缩价格,从其他网站获得最低价格 问题是我的xml中有7000多个URL,所以我的程序每次都会出错 怎么办?我如何解决它 def parse_sitemap (url): resp = requests.get(XXXX) for u in urls: loc = u.find ('lo
def parse_sitemap (url):
resp = requests.get(XXXX)
for u in urls:
loc = u.find ('loc').string
# not a sitemap requirement skip if not present
out.append ([loc])
return out
def get_sku (u):
html = requests.get(u)
bsObj = BeautifulSoup(html.content,'xml')
sku = bsObj.find('span',attrs={'itemprop':'sku'}).get_text()
return sku
def get_price ( u):
try:
html = requests.get(u)
bsObj = BeautifulSoup(html.content,'xml')
price = bsObj.find('span',attrs={'itemprop':'price'}).get_text()
price = str(price).replace(' ₪','')
return price
except:
return 'no price'
def get_zapPrice (makat):
try:
check ='https://www.zap.co.il/search.aspx?keyword='+makat
r = requests.get(check)
html = requests.get(r.url)
bsObj = BeautifulSoup(html.content,'html.parser')
zapPrice = bsObj.select_one('div.StoresLines div.PriceNum').text.strip().replace(' ₪','')
return zapPrice
except:
return 'no zap product'
def get_zapStoreName (makat):
try:
check ='https://www.zap.co.il/search.aspx?keyword='+makat
r = requests.get(check)
html = requests.get(r.url)
bsObj = BeautifulSoup(html.content,'html.parser')
storeName = bsObj.select_one('div.StoresLines
div.BuyButtonsTxt').text.strip().replace('ב-','')
return storeName
except:
return 'no zap product'
for u in urls:
ws1 [ 'A1' ] = u
makat = get_sku(u)
ws1 [ 'F1' ] = makat
zapPrice = get_zapPrice(makat)
ws1['I1'] = zapPrice
storeName = get_zapStoreName(makat)
ws1['J1'] = storeName
ws1.insert_rows(1)
ws1.append ([])
print("writing product no." + str(i))
ws1['F1'] = 'makat'
ws1['I1'] = 'zap price'
ws1['J1'] = 'zap store'
wb.save ("sample.xlsx")
wb.close ()
print ('end')
我没有写我所有的代码-基本的是在这里
每个def都是从请求开始的。获取,获取我想要的并返回它
之后,我将它写入excel文件
我在1000个URL检查后遇到的问题。。。
问题是什么???请添加完整的错误回溯。在不知道确切问题的情况下,无法尝试回答您的问题。请添加完整的错误回溯。在不知道确切问题的情况下,试图回答你的问题是不可能的。