Chào các bác, các bác giúp em với ạ!
Em muốn tìm 1 chuỗi string trên content của web đã được request.
Thế nhưng có 1 vấn đề đó là em dùng điều kiện if trong vòng lặp while, nếu string được tìm thấy, chương trình chạy bình thường, if không tìm thấy string thì chương trình quay trở lại vòng while.
loc1 = res1.find('<dd class="wikidevi_url"><a href=')
res1 = res1[loc1+34 :dai1]
cuoi1 = res1.find("' class='urlextern'")
LinkWiki = res1[0:cuoi1]
if res1.find('<dd class="wikidevi_url"><a href=') != False :
rcsv = open('/home/zuoimj/Desktop/Crawler/brand.csv')
reader = csv.reader(rcsv, delimiter=',')
next(reader)
for k in reader:
url = LinkWiki
b = requests.get(url)
res2=b.content
dai2 = len(res2)
#Tim CPU1
loc2 = res2.find('CPU1')
res2 = res2[loc2+4 :dai2]
cuoi2 = res2.find('FLA1')
CPU1 = res2[0:cuoi2]
res2 = res2[cuoi2:dai2]
#Tim FLA1
loc2 = res2.find('FLA1:</b> <b><span class="smw-highlighter" data-type="3" data-state="inline" data-title="Quantity"><span class="smwtext">')
res2 = res2[loc2 +121: dai2]
cuoi2 = res2.find('</span>')
FLA1 = res2[0:cuoi2]
res2 = res2[cuoi2:dai2]
#Tim RAM1
loc2 = res2.find('RAM1:</b> <b><span class="smw-highlighter" data-type="3" data-state="inline" data-title="Quantity"><span class="smwtext">')
res2 = res2[loc2+121:dai2]
cuoi2 = res2.find('</span>')
RAM1 = res2[0:cuoi2]
else:
CPU1 = ''
FLA1 = ''
RAM1 = ''
chỗ if ở trên ý ạ, em để là False không được các bác ạ. While 1 em tìm ra được link và lệnh b.request dùng hoạt động bt, nhưng While 2 thì không có, và hình như nó ko pass và nó request tiếp, thế nên xảy ra lỗi ở đó.