for i in range(length):
# print(i)
driver.execute_script("window.history.go(-1)")
range = driver.find_element_by_xpath("(//a[@class = 'button'])[i]").click()
content2 = driver.page_source.encode('utf-8').strip()
soup2 = BeautifulSoup(content2,"html.parser")
name2 = soup2.find('h1', {'data-qa-target': 'ProviderDisplayName'}).text
phone2 = soup2.find('a', {'class': 'click-to-call-button-secondary hg-track mobile-click-to-call'}).text
print(name2, phone2)
嘿,伙计,我正在努力为这个网站上的每个人刮取名字和姓氏、电话:https://www.healthgrades.com/family-marriage-counseling-directory。我希望(l.4)按钮适应变量(I)。如果我手动将i改为一个数字,一切都会正常工作。但是,一旦我把它放在变量中,它就不起作用了,非常感谢任何帮助
与此相反:
这样做:
更新1:
输出:
更新2:
相关问题 更多 >
编程相关推荐