脚本宝典收集整理的这篇文章主要介绍了数据采集与融合技术-第五次作业,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
复制xpath路径,传入关键字
实现点击搜索按钮
@H_777_97@but = self.driver.find_element_by_xpath('//*[@id="seArch"]/div/div[2]/button') but.click() time.sleep(10)
实现滚动翻页
for i in range(33):
self.driver.execute_script("VAR a = window.innerHeight;window.scrollBy(0,a*0.5);")
time.sleep(0.5)
分析商品页面,每个商品的信息都在li标签中html = self.driver.find_elements_by_xpath('//*[@id="J_goodsList"]/ul/li')#爬取所有li标签
遍历每个li,爬取节点信息
for ITem in range(len(html)):
try:
mMark = html[item].find_element_by_xpath('./div//div[@class="p-name"]/a/em/font[1]').text
print(mMark)
except Exception as err:
mMark = " "
mPrice = html[item].find_element_by_xpath('./div//div[@class="p-price"]/strong/i').text
mNote = html[item].find_element_by_xpath('./div//div[@class="p-name"]/a/em').text
src = html[item].find_element_by_xpath('./div//div[@class="p-img"]/a/img').get_attribute('src')
self.picSave(src)
self.db.insert(self.count, mMark, mPrice, mNote, str(self.count)+".jpg")
self.count += 1
实现翻页
if self.page < 2:
self.page += 1
nextPage = self.driver.find_element_by_xpath('//*[@id="J_bottomPage"]/span[1]/a[9]')
nextPage.click()
#再次执行爬取函数
self.Mining()
# 登录入口
DL = self.driver.find_element_by_xpath('//*[@id="app"]/div/div/div[1]/div[3]/div[3]/div')
DL.click()
# 点击其他方式登录
QTDL = self.driver.find_element_by_xpath('//span[@class="ux-login-set-scan-code_ft_back"]')
QTDL.click()
# 点击手机登录
phoneDL = self.driver.find_element_by_xpath('//ul[@class="ux-tabs-underline_hd"]/li[2]')
phoneDL.click()
# 切换浮动窗口
phoneI = self.driver.find_element_by_xpath('//div[@class="ux-LOGin-set-container"][@id="j-ursContainer-1"]/iframe')
self.driver.switch_to.frame(phoneI)
# 输入手机号
phoneNum = self.driver.find_element_by_xpath('//*[@id="phoneipt"]')
phoneNum.send_keys(USERNAME)
# 输入密码
phonePassword = self.driver.find_element_by_xpath('//div[@class="u-input box"]/input[2]')
phonePassword.send_keys(PASSWORD)
# 点击登录,等待登录成功
DlClick = self.driver.find_element_by_xpath('//*[@id="submitBTn"]')
DlClick.click()
time.sleep(10)
# 进入我的课程
myClass = self.driver.find_element_by_xpath('//div[@class="_1Y4Ni"]/div')
myClass.click()
time.sleep(5)
分析课程页面,每个课程的信息都在一个div标签中
# 爬取每个课程的div标签
html = self.driver.find_elements_by_xpath('//*[@id="j-coursewrap"]/div/div/div')
遍历每个div,爬取节点信息
# 爬取信息
for item in html:
print(self.count)
cCourse = item.find_element_by_xpath('./div//div[@class="text"]/span[@class="text"]').text
print(cCourse)
cCollege = item.find_element_by_xpath('./div//div[@class="school"]/a').text
print(cCollege)
cSchedule = item.find_element_by_xpath('./div//div[@class="text"]/a/span').text
print(cSchedule)
cCourseStatus = item.find_element_by_xpath('./div//div[@class="course-status"]').text
print(cCourseStatus)
src = item.find_element_by_xpath('./div//div[@class="img"]/img').get_attribute("src")
print(src)
self.picSave(src, cCourse)
self.db.insert(self.count, cCourse, cCollege, cSchedule, cCourseStatus, src)
self.count += 1
实现翻页
nextPage = self.driver.find_element_by_xpath('//*[@id="j-coursewrap"]/div/div[2]/ul/li[4]/a')
# 实现翻页
if nextPage.get_attribute('class') != "th-bk-disable-gh":
print(1)
nextPage.click()
time.sleep(5)
# 再次执行爬取函数
self.Mining()
任务一:Python脚本生成测试数据执行python文件
查看生成数据任务二:配置Kafka执行source
任务三:安装Flume客户端最后安装Flume
重启服务任务四:配置Flume采集数据
以上是脚本宝典为你收集整理的数据采集与融合技术-第五次作业全部内容,希望文章能够帮你解决数据采集与融合技术-第五次作业所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。