爬取资讯网站的新闻并保存到excel
2018-01-30 18:25
344 查看
#!/usr/bin/env python
#* coding:utf-8 *
#author:Jacky
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from bs4 import BeautifulSoup
import xlwt
driver = webdriver.Firefox()
driver.implicitly_wait(3)
first_url = 'http://www.yidianzixun.com/channel/c6'
driver.get(first_url)
driver.find_element_by_class_name('icon-refresh').click()
for i in range(1, 90):
driver.find_element_by_class_name('icon-refresh').send_keys(Keys.DOWN)
soup = BeautifulSoup(driver.page_source, 'lxml')
print soup
articles=[]
for article in soup.findall(class='item doc style-small-image style-content-middle'):
title= article.find(class_='doc-title').gettext()
source=article.find(class='source').gettext()
comment=article.find(class='comment-count').get_text()
link='http://www.yidianzixun.com'+article.get('href')
articles.append([title,source,comment,link])
print articles
driver.quit()
wbk=xlwt.Workbook(encoding='utf-8')
sheet=wbk.add_sheet('yidianzixun')
i=1
sheet.write(0, 0, 'title')
sheet.write(0, 1, 'source')
sheet.write(0, 2, 'comment')
sheet.write(0, 3, 'link')
for row in articles:
#print row[0]
sheet.write(i,0,row[0])
sheet.write(i,1,row[1])
sheet.write(i,2,row[2])
sheet.write(i,3,row[3])
i +=1
wbk.save(r'zixun\zixun.xls')
#* coding:utf-8 *
#author:Jacky
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from bs4 import BeautifulSoup
import xlwt
driver = webdriver.Firefox()
driver.implicitly_wait(3)
first_url = 'http://www.yidianzixun.com/channel/c6'
driver.get(first_url)
driver.find_element_by_class_name('icon-refresh').click()
for i in range(1, 90):
driver.find_element_by_class_name('icon-refresh').send_keys(Keys.DOWN)
soup = BeautifulSoup(driver.page_source, 'lxml')
print soup
articles=[]
for article in soup.findall(class='item doc style-small-image style-content-middle'):
title= article.find(class_='doc-title').gettext()
source=article.find(class='source').gettext()
comment=article.find(class='comment-count').get_text()
link='http://www.yidianzixun.com'+article.get('href')
articles.append([title,source,comment,link])
print articles
driver.quit()
wbk=xlwt.Workbook(encoding='utf-8')
sheet=wbk.add_sheet('yidianzixun')
i=1
sheet.write(0, 0, 'title')
sheet.write(0, 1, 'source')
sheet.write(0, 2, 'comment')
sheet.write(0, 3, 'link')
for row in articles:
#print row[0]
sheet.write(i,0,row[0])
sheet.write(i,1,row[1])
sheet.write(i,2,row[2])
sheet.write(i,3,row[3])
i +=1
wbk.save(r'zixun\zixun.xls')
相关文章推荐
- 爬虫记录(6)——爬虫实战:爬取知乎网站内容,保存到数据库,并导出到Excel
- 一些国外的信息咨询和新闻资讯不错的网站
- 网站如何让新闻资讯分享给更多的人?
- Python爬虫项目,获取所有网站上的新闻,并保存到数据库中,解析html网页等(未完待续)
- 新闻资讯网站
- 高仿砍柴网自媒体新闻资讯网站源码(织梦DEDE内核+手机WAP版)
- 做新闻资讯网站应该注意的几点 推荐
- IT业界新闻资讯网站推荐
- 网站如何让新闻资讯分享给更多的人?
- 模拟登陆学校教务处网站,并保存到成绩为excel格式
- python3爬虫 爬取图片,爬取新闻网站文章并保存到数据库
- 帝国CMS-导入网站后,生成不了新闻
- SSH网站实录(7)新闻模块
- 简单的网站页面计数器(防刷新,用txt文件保存)
- Google推出新闻资讯的图片版本
- html保存表格到word,excel.
- 总结一下,近半年来自己保存的iphone开发相关的网站
- c# 应用NPOI 获取Excel中的图片,保存至本地的算法
- 用WS_DOWNLOAD保存为本地Excel,中文出现乱码解决
- 如何保存原来的网站数据且换后台环境?