я получаю ошибки подключения в моей программе Python - PullRequest
0 голосов
/ 01 марта 2019

Вы пытались запустить мою программу, но каждый раз, когда я получаю сообщение об ошибке в середине запуска, моя программа делает это: 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 ('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')

я не написал весь свой код - по сути, здесь есть каждое определение, начинающееся с request.get, получаю то, что хочу, и возвращаю его после этого, пишу в файл Excel

проблема, которую я получаю после 1000 проверок URL-адресов ... в чем проблема ??

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...