某徒步旅游网站python爬虫小练习
2017-07-18 22:19
471 查看
yxk周边游网站python爬虫小练习(跨页面)
代码很简单,关键一个是 encoding="utf_8_sig"
, 否则乱码,注意writerow()
处理list
import warnings warnings.filterwarnings("ignore")
import csv from urllib.request import urlopen from bs4 import BeautifulSoup csvFile=open("C:\\Users\\dell-pc\\Documents\\Python Scripts\\Untitled Folder\\uxiake.csv","wt",newline="",encoding="utf_8_sig") writer=csv.writer(csvFile) try: for i in range(9): num=str(i+1) html=urlopen("http://www.youxiake.com/around?place_id=2&days=0&month=0&holiday=0&price=0&tag=0&class_id=0>s=>e=&p="+num) bs0bj=BeautifulSoup(html) total=bs0bj.find("div",{"class":"m-bd-con current"}).findAll("div",{"class":"act-item clearfix"}) for i in total: putin=[] head=i.find("h3").find("a").get_text() style=i.find("h3").find("span").get_text() place=i.find("div",{"class":"z-subMsg"}).findAll("p")[0].get_text() days=i.find("span",{"class":"days"}).get_text() venue=i.find("span",{"class":"venue"}).get_text() putin.append([head,style,place,days,venue]) for i in putin: writer.writerow(i) finally: csvFile.close()
相关文章推荐
- python爬取携程和蚂蜂窝的景点评论数据\python爬取携程评论数据\python旅游网站评论数据爬虫
- python爬虫学习(上)——目标网站分析
- Python小爬虫练习
- Python爬虫之从网站图片中抓取文字
- python 爬虫练习二, 爬取python标准库为pdf
- python爬虫练习--爬取某城市历史气象数据(待优化)
- python爬虫 抓取一个网站的所有网址链接
- python爬虫小练习之五:requests库小练习(58同城2手手机简单)
- Python爬虫:模拟登录带验证码网站
- Python爬虫爬取美剧网站
- python爬虫+django 搭建学分积查询网站
- Python爬虫抓取某音乐网站MP3(下载歌曲、存入Sqlite)
- python爬虫模拟登录网站(一)-----豆瓣
- python 爬虫scrapy框架练习
- python爬虫基础登----网站登录
- python+selenium+unittest,爬虫电影网站
- Python入门-编写抓取网站图片的爬虫-正则表达式
- 爬虫练习二:GUI+下载百思不得姐网站视频
- Python爬虫爬取美剧网站
- python练习1(简单爬虫)