如何解决刮瑙克里
我正在尝试抓取https://www.naukri.com/information-technology-jobs-in-hyderabad-secunderabad-secunderabad的页数。我正在尝试获取公司名称,名称和技能。我已经使用了检查和复制xpath。我面临多次单击“下一步”按钮并获取数据的问题。
for i in range(1,21):
company_name.append(driver.find_element_by_xpath('//*[@id="root"]/div[4]/div[2]/section[2]/div[2]/article['+str(i)+']/div[1]/div/div/a[1]').text)
time.sleep(3)
designation.append(driver.find_element_by_xpath('//*[@id="root"]/div[4]/div[2]/section[2]/div[2]/article['+str(i)+']/div[1]/div/a').text)
time.sleep(3)
skills.append(driver.find_element_by_xpath('//*[@id="root"]/div[4]/div[2]/section[2]/div[2]/article['+str(i)+']/ul').text)
解决方法
您可以使用以下xpath单击下一步:
while True:
next_page_btn = driver.find_elements_by_xpath("//*[@class='pagination mt-64 mb-60']//div/child::*")
if len(next_page_btn) < 1:
print("No more pages left")
break
else:
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.LINK_TEXT,'/information-technology-jobs-in-hyderabad-secunderabad-2'))).click()//or use partial link text
,
您无需单击下一步按钮即可转到下一页。
https://www.naukri.com/information-technology-jobs-in-hyderabad-secunderabad-10
https://www.naukri.com/information-technology-jobs-in-hyderabad-secunderabad-20
如果您观察上述URL,则在每个URL末尾给出的页面导航编号就是这种分隔方式。
要访问所有搜索结果页面,您需要遍历范围并将数字格式化为URL并抓取数据。
例如: 对于范围在(1,1000)中的ii: URL =“ https://www.naukri.com/information-technology-jobs-in-hyderabad-secunderabad-{}".format(ii) 您的提取器在这里。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。