大佬教程收集整理的这篇文章主要介绍了美丽的汤/蟒蛇不会摆脱 while 循环,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试构建我的第一个 webscraper,所以请原谅我的代码一团糟。
但是我遇到了一个问题,我的程序卡在我的 while 循环中。
我想遍历总页数。所以我认为这应该可以通过 while 循环实现:
While huIDigePagina (means current page in dutch) <= @R_797_10586@lePagina:
...
...
huIDigePagina = huIDigePagina + 1
然而,即使在“+ 1”之后,我的 while 循环仍在继续。 或者当它工作时,我收到一个错误,我的汤.find 遇到了一个 nonetype ...... 我试过跳出 while 循环,但也没有用。
这是代码的全部内容:
links = []
GeoCodes = []
coordinaten = []
content = driver.page_source
soup = BeautifulSoup(content,features="HTMl.parser")
for body in soup.findAll('div',{'class': 'span-20 last'}):
numberPages = body.find('div',{'ID': 'ctl00_Contentbody_ResultsPanel'}).find('table',{'class': 'NoBottomSpacing'}).findAll('b')
print(numberPages)
huIDigePagina = 1
@R_797_10586@lePagina = int(numberPages[2].text)
while huIDigePagina <= @R_797_10586@lePagina:
for row in soup.findAll('tr',{"class":["SolIDRow Data bordertop","BeginnerRow Data bordertop","AlternaTingRow Data bordertop"]}):
checkBox = row.find('td').input
if checkBox is not None:
cachecodeLocator = row.find("td",{"class": "Merge"}).findNextSibling("td").text
#print(cachecodeLocator)
if "GC" in cachecodeLocator:
b = cachecodeLocator
c = re.findall("GC.....",b)
GeoCodes.append(c[0])
cachePage = row.find("td",{"class": "Merge"}).findNextSibling("td").a['href']
if cachePage is not None:
driver.get(str(cachePagE))
coordcontent = driver.page_source
coordinatenpagina = BeautifulSoup(coordcontent,features="HTMl.parser")
coordinaat = coordinatenpagina.find('div',class_='span-9').p.span.strong.span.text
coordinaten.append(coordinaat)
driver.BACk()
links.append(cachePagE)
#driver.get(str(CachepagE))
nextPage = len(numberPages) - 1
print(huIDigePagina,@R_797_10586@lePagina)
if huIDigePagina != @R_797_10586@lePagina:
driver.find_elemenT_By_xpath("//*[@ID='ctl00_Contentbody_ResultsPanel']/table[1]/tbody/tr/td[2]/a[{}]".format(nextPagE)).click()
content2 = driver.page_source
soup = BeautifulSoup(content2,features="HTMl.parser")
body2 = soup.find('div',{'class': 'span-20 last'})
numberPages = body2.find('div',{'class': 'NoBottomSpacing'}).findAll('b')
print(numberPages)
huIDigePagina = huIDigePagina + 1
@R_797_10586@lePagina = int(numberPages[2].text)
print(huIDigePagina,@R_797_10586@lePagina)
if huIDigePagina == @R_797_10586@lePagina:
break
df = pd.DataFrame({'GeoCodes': GeoCodes,'links': links,'coordinaten': coordinaten})
df.to_csv('C_And_C.csv',index=True,enCoding='utf-8')
driver.close()
这里有一些似乎有效的更新代码?
links = []
GeoCodes = []
coordinaten = []
content = driver.page_source
soup = BeautifulSoup(content,features="HTMl.parser")
for body in soup.findAll('div',class_='span-9').p.span.strong.span.text
coordinaten.append(coordinaat)
driver.BACk()
links.append(cachePagE)
#driver.get(str(CachepagE))
nextPage = len(numberPages) - 1
huIDigePagina = huIDigePagina + 1
if huIDigePagina > @R_797_10586@lePagina:
break
driver.find_elemenT_By_xpath("//*[@ID='ctl00_Contentbody_ResultsPanel']/table[1]/tbody/tr/td[2]/a[{}]".format(nextPagE)).click()
content2 = driver.page_source
soup = BeautifulSoup(content2,{'class': 'NoBottomSpacing'}).findAll('b')
print(numberPages)
@R_797_10586@lePagina = int(numberPages[2].text)
print(huIDigePagina,@R_797_10586@lePagina)
df = pd.DataFrame({'GeoCodes': GeoCodes,enCoding='utf-8')
driver.close()
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的美丽的汤/蟒蛇不会摆脱 while 循环全部内容,希望文章能够帮你解决美丽的汤/蟒蛇不会摆脱 while 循环所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。