资源简介
对神舟租车动态网页的爬虫。高效,且爬取的数据为结构化数据。不用后续进行清理
代码片段和文件信息
#-*- coding: UTF-8 -*-
import sys
import os
import time
import urllib
import urllib2
import codecs
import requests
import numpy as np
import random
from collections import OrderedDict
from bs4 import BeautifulSoup
from openpyxl import Workbook
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import *
reload(sys)
sys.setdefaultencoding(‘utf8‘)
def html_file_analysis(storeHtml):
spider_list=[]
bs=BeautifulSoup(open(storeHtml) ‘html.parser‘)
for tag in bs.find_all(“tbody“):
for child_tag in tag.contents:
#print(“the child tag is “ child_tag)
try:
info=child_tag.find(“td“ class_=“info“)
name=info.find(“p“ class_=“name“)
other_info=info.find(“p“ class_=“oth“)
ord_info=child_tag.find(“td“ class_=“ord“)
pri_list = ord_info.select(‘em[class=num]‘)
if len(pri_list)==1:
pri_list = ord_info.find_all(“em“ {‘class‘:“num od_chagst“})+pri_list
if len(pri_list)==0:
pri_list = ord_info.find_all(“em“ {‘class‘:‘num od_full‘})
assert(len(pri_list)==2)
name=name.string.strip()
other_info=other_info.string.strip()
#print(name)
price_per_day = pri_list[0].string.strip()
price_total = pri_list[1].string.strip()
#print(price_total)
spider_list.append([name other_info price_per_day price_total])
except:
continue
#finally:
return spider_list
def html_analysis(page_source):
spider_list=[]
if page_source is None:
return None
bs=BeautifulSoup(page_source ‘html.parser‘)
for tag in bs.find_all(“tbody“):
for child_tag in tag.contents:
#print(“the child tag is “ child_tag)
try:
info=child_tag.find(“td“ class_=“info“)
name=info.find(“p“ class_=“name“)
other_info=info.find(“p“ class_=“oth“)
ord_info=child_tag.find(“td“ class_=“ord“)
pri_list = ord_info.select(‘em[class=num]‘)
if len(pri_list)==1:
pri_list = ord_info.find_all(“em“ {‘class‘:“num od_chagst“})+pri_list
if len(pri_list)==0:
pri_list = ord_info.find_all(“em“ {‘class‘:‘num od_full‘})
assert(len(pri_list)==2)
name=name.string.strip()
other_info=other_info.string.strip()
#print(name)
price_per_day = pri_list[0].string.strip()
price_total = pri_list[1].string.strip()
#print(price_total)
spider_list.append([name other_info price_per_day price_total])
except:
相关资源
- python实现SGBM图像匹配算法
- python实现灰度直方图均衡化
- scrapy_qunar_one
- Python学习全系列教程永久可用
- python简明教程.chm
- 抽奖大转盘python的图形化界面
- 双边滤波器实验报告及代码python
- python +MYSQL+HTML实现21蛋糕网上商城
- Python-直播答题助手自动检测出题搜索
- OpenCV入门教程+OpenCV官方教程中文版
- Python 串口工具源码+.exe文件
- Python开发的全栈股票系统.zip
- Python操作Excel表格并将其中部分数据写
- python书籍 PDF
- 利用python绘制散点图
- python+labview+No1.vi
- 老男孩python项目实战
- python源码制作whl文件.rar
- python3.5可用的scipy
- PYTHON3 经典50案例.pptx
- 计算机科学导论-python.pdf
- python模拟鼠标点击屏幕
- windows鼠标自动点击py脚本
- 鱼c小甲鱼零基础学python全套课后题和
- Python 练习题100道
- Practical Programming 2nd Edition
- wxPython Application Development Cookbook
- python 3.6
- Python 3.5.2 中文文档 互联网唯一CHM版本
- python3.5.2.chm官方文档
评论
共有 条评论