python语法基础

# 单引号注释 print()
'''
三引号注释法
print()
print()

'''

a="qwertyuiop"
b="qwertyuio"
sa = set(a)
print(sa)

sb = set(b)
print(sb)

sa|sb
sa&sb

a={"name":"zhangsan","age":"20","sex":"0"}
print(a["name"])
print(a["age"])




a=10
b=1
if(a>9):
    print(a)
    if(b==9):
        print(b)
elif(a<10):
    print("abc")
'''    
a=5
while a<10:
    print("hello")

'''
    
a=['a','b','c','d','e','f']
'''
for i in a:
    print(i)

for i in range(0,9):
     print("hello")
'''
for i in range(0,9):
    if(i==7):
        continue;
    print(i)

for i in range(0,9):
    if(i==5):
        break;
    print(i)


# 导入谁,谁就接
#方式一:
import urllib
from urllib.request import urlopen
data1 = urllib.request.urlopen("http://www.baidu.com").read()
#print(data1)
print(len(data1))

# 方式二:
data2=urlopen("http://jd.com").read()
#print(len(data2))
print(len(data2))

# 方式三:
from urllib import request
data3=request.urlopen("http://jd.com").read()
print(len(data3))

# 打开文件,写入
fh1 = open("C:/Users/tao/Desktop/python/file1.txt","w")
fh1.write("你好,开始写入数据")
fh1.close()

# 打开文件,读写
fh2 = open("C:/Users/tao/Desktop/python/file1.txt","r")
data2=fh2.read()
print(data2)


#按行读取
fh2 = open("C:/Users/tao/Desktop/python/file1.txt","r")
while True:
    line=fh2.readline()
    if len(line)==0:
        break
    print(line)
fh2.close()
    
# 异常处理
try:
    print("zhengchang")
    printss("hell")
except Exception as eer:
    print(err)
    print("hi me to")
    
# 作业


# 网络爬虫能做什么事情?
#1、搜索引擎
#2、采集金融数据
#3、采集商品数据
#4、自动过滤广告
#5、采集竞争对手的客户数据
#6、采集行业相关数据,进行数据分析

# 下载路径:https://www.lfd.uci.edu/~gohlke/pythonlibs/
# 命令安装: pip install 软件名称

#网络爬虫原理

# 通用 和聚焦网络爬虫


# 正则表达式

import re

pat="yue"
string = "http://www.baidu.com"
res = re.search(pat,string)
print(res)


pat="\n"
string3='''242353243qwerty
qqqqqq'''
res3 = re.search(pat,string3)
print(res3)


\w 匹配任意字母数字或则下划线
\d 匹配任意一个十进制数
\s 匹配任意一个空白字符

\W 匹配任意字符,除了字母数字或则下划线
\D 匹配任意字符,除了十进制数
\S 匹配任意字符,除了空白字符

^ 匹配字符串开始位置
$ 匹配字符串结束位置
* 匹配0次1次多次
?匹配0次1次
+ 匹配0次多次
. 匹配任意字符
| 匹配或


# 模式修正符

I 忽略大小写
M 多行匹配
L 本地化匹配 (忽略)
U unicode 修正符
S 点也能匹配


s{5,7} 表示s出现5次最多7次


path1 = "python"
path2 = "python"
string = "qwqwqwqwqwqwPythonweb"
rst =re.search(pat1,string)
print(rst)
rst =re.search(pat1,string,re.I) # 使用修正符


#元组表达式
import re

pat = "pyth[jsz]n"
string = "asasasasasaspythsndd"
rst = re.search(pat,string)
print(tst)


pat = ".python..."
string = "gowebpythonwhoareyou"
rst = re.search(pat,string)
print(rst)




#贪婪模式和懒惰模式
# 贪婪模式的核心就是尽可能多的匹配;
# 懒惰模式的核心就是尽可能少的匹配;

par1="p.*y"
pat2="p.*?y"
string ="abcdpythonthouhpy"

###############################################################
# 爬虫出版社名称
# 步骤:一先爬虫下来 二、写到记事本


import urllib.request
data=urllib.request.urlopen("https://read.douban.com/provider/all").read()
data=data.decode("utf-8")
import re

pat='<div class="name">(.*?)</div>'
mydata=re.compile(pat).findall(data)
mydata

# 打开文件,写入
fh1 = open("C:/Users/tao/Desktop/python/file1.txt","w")
for i in range(0,len(mydata)):
fh1.write(mydata[i]+"\n")

fh1.close()

##############################################################

# Urllib库基础

import urllib.request.urlcleanup()

# 列如:urllib.request
# urlretrieve() 使用,即将网页爬到本地所对应的指定地址位置。
# urlcleanup() 使用,即清缓存。
# urlopen()
# info()    获取爬虫信息
# getcode() 获取爬虫状态
# geturl()  获取爬虫哪个链接


import urllib.request
urllib.request.urlretrieve("http://www.hao123.com",filename="C:/Users/tao/Desktop/python/20181121/1.html")


file = urllib.request.urlopen("http://www.hao123.com")
file.info()
file.getcode()
file.geturl()

# 设置超时时间
file = urllib.request.urlopen("http://www.hao123.com",timeout=10)


for i in range(0,100):
    try:
        file=urllib.request.urlopen("http://www.hao123.com",timeout=1)
        data=file.read()
        print(len(data))
    except Exception as e:
        print("出现异常:"+str(e))

# 自动模拟HTTP请求 post和get


import urllib.request
keywd="python"
keywd= urllib.request.quote(keywd)
url="http://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&ch=&tn=98779107_hao_pg&bar=&wd="+keywd
req=urllib.request.Request(url)
data=urllib.request.urlopen(req).read()
fh=open("C:/Users/tao/Desktop/python/20181121/getPython.html","wb")
fh.write(data)
fh.close()


import urllib.request
import urllib.parse
url = ""
mydata= urllib.parse.urlencode({
"name":"tao.com",
"pass":"123456"
    }).encode("utf-8")
req = urllib.request.Request(url,mydata)
data = urllib.request.urlopen(req).read();
fh=open("C:/Users/tao/Desktop/python/20181121/postPython.html","wb")
fh.write(data)
fh.close()


#异常处理

URLError产生的情况:
1、连不上服务器;
2、远程URL不存在触发了URL
3、本地没有网络
4、触发了HTTPError子类

import urllib.error
import.urllib.request

try:
    urllib.request.urlopen("http://www.youtube.com")
except urllib.error.URLError as e:
    if hasattr(e,"code"):
       print(e.code)
    if hasattr(e,"reason"):
       print(e.reason)
        
# 浏览器伪装技术原理 及浏览器伪装技术实战

import urllib.request
url = "https://blog.csdn.net/ITdada"
headers= ("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36")
opener = urllib.request.build_opener()
opener.addheaders=[headers]
data= opener.open(url).read()
fh=open("C:/Users/tao/Desktop/python/20181121/weizhuangpacong.html","wb")
fh.write(data)
fh.close()





import urllib.request
import re
data=urllib.request.urlopen("http://news.sina.com.cn/").read()
data2=data.decode("utf-8","ignore")  # 表示设置字符编码,后面表示忽略
pat = 'href="(http://news.sina.com.cn/.*?)"'
allurl = re.compile(pat).findall(data2)
for i in range(0,len(allurl)):
    try:
        print("第"+str(i)+"次爬取")
        thisurl=allurl[i]
        file="C:/Users/tao/Desktop/python/20181125/sina/"+str(i)+".html"
        urllib.request.urlretrieve(thisurl,file)
        print("---成功--")
    except urllib.error.URLError as e:
        if hasattr(e,"code"):
           print(e.code)
        if hasattr(e,"reason"):
           print(e.reason)


# 作业练习

import urllib.request
import re
url="http://blog.csdn.net"
headers= ("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36")
opener = urllib.request.build_opener()
opener.addheaders = [headers]
urllib.request.install_opener(opener)
data =urllib.request.urlopen(url).read().decode("utf-8","ignore")
pat ='<h3 class="company_name"><a href="(.*?)"'
result = re.compile(pat).findall(data)
print(result)
for i in range(0,len(result)):
    try:
        print("第"+str(i)+"次爬取")
        file="C:/Users/tao/Desktop/python/20181125/csdn/"+str(i)+".html"  #str是个类不能使用下标,这里应该改成小括号 
        urllib.request.urlretrieve(result[i],filename= file)
        print("---成功--")
    except urllib.error.URLError as e:
        if hasattr(e,"code"):
           print(e.code)
        if hasattr(e,"reason"):
           print(e.reason)


# http://www.xicidaili.com/ 西刺免费代理ip
# url   表示爬虫的IP地址
# proxy_addr 表示代理服务器的ip地址

import urllib.request
def use_proxy(url,proxy_addr):
    proxy = urllib.request.ProxyHandler({"http":proxy_addr})
    opener = urllib.request.build_opener(proxy,urllib.request.HTTPHandler)
    urllib.request.install_opener(opener)
    data =urllib.request.urlopen(url).read().decode("utf-8","ignore")
    return data

proxy_addr="183.47.2.201:30278"
url = "http://www.baidu.com"

data = use_proxy(url,proxy_addr)
print(len(data))
    

#图片爬虫



import urllib.request
import urllib.error
import re
keyname="短裙"
key = urllib.request.quote(keyname)
headers=("User-Agent","Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:63.0) Gecko/20100101 Firefox/63.0")
opener=urllib.request.build_opener()
opener.addheaders = [headers]
urllib.request.install_opener(opener)
for i in range(1,150):
    url="https://s.taobao.com/list?spm=a217f.8051907.312344.12.51533308iMkVIU&q="+key+"&cat=16&seller_type=taobao&oetag=6745&source=qiangdiao&bcoffset=0&s="+str(i*60)
    print(url)
    data=urllib.request.urlopen(url).read().decode("utf-8","ignore")
    pat='{"picUrl":"//(.*?)"'
    imagelist=re.compile(pat).findall(data)
    print(imagelist)
    for j in range(0,len(imagelist)):
        try:
            thisimg=imagelist[j]
            thisimgurl="http://"+thisimg
            file="C:/Users/tao/Desktop/python/20181127/taobao/"+str(i)+str(j)+".jpg"
            urllib.request.urlretrieve(thisimgurl,filename= file)
            print("---成功--")
        except urllib.error.URLError as e:
            if hasattr(e,"code"):
               print(e.code)
            if hasattr(e,"reason"):
               print(e.reason) 



# demo

import re  
import urllib.request  
import urllib.error  
import pandas as pd  
from pandas import DataFrame,read_csv  
#设置正则表达式  
title_pat  =  '"raw_title":"(.*?)",'  
price_pat  =  '"view_price":"(.*?)",'  
loc_pat  =  '"item_loc":"(.*?)",'  
sale_pat  =  '"view_sales":"(.*?)人付款",'  
comment_pat  =  '"comment_count":"(.*?)",'  
#设置要进行爬取的网址  
fh=open('./taobao.txt','w')  
#设置搜索关键词  
key  =  '零食'  
key  =  urllib.request.quote(key)  
for i in range(1,101):  
    try:  
        print('正在爬取第'+str(i)+"页")  
        url="http://s.taobao.com/search?q="+key+"&imgfile=&js=1&stats_click=search_radio_all%3A1&initiative_id=staobaoz_20180514&ie=utf8&bcoffset=0&ntoffset=6&p4ppushleft=1%2C48&s="+str(i-1)*44  
        #设置报头,封装请求并爬取
        headers=("user-agent",'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.170 Safari/537.36')  
        opener=urllib.request.build_opener()  
        opener.addheaders=[headers]  
        urllib.request.install_opener(opener)  
        req=urllib.request.Request(url)  
        data=urllib.request.urlopen(req).read().decode('utf-8','ignore')  
        #提取title、price、location、sale、comment
        title=re.compile(title_pat).findall(data)  
        price=re.compile(price_pat).findall(data)  
        loc=re.compile(loc_pat).findall(data)  
        sale=re.compile(sale_pat).findall(data)  
        comment=re.compile(comment_pat).findall(data)
        #写入文件  
        mydata=list(zip(title,price,loc,sale,comment))  
        mydataf=pd.DataFrame(data=mydata)  
        fh.write(str(mydataf))  
    except urllib.error.URLError as e:   #抓取异常并输出
        print('第'+str(i)+'页爬取失败')  
        if hasattr(e,'reason'):  
            print(e.reason)  
        if hasattr(e,'code'):  
            print(e.code)  
    print('第'+str(i)+'页爬取成功')  
fh.close() 


# demo 练习 http://www.58pic.com

import urllib.request
import re
for i in range(1,10):
    pageurl="http://www.58pic.com/piccate/4-126-328-default-0_2_0_0_default_0-"+str(i)+".html"
    data = urllib.request.urlopen(pageurl).read().decode("utf-8","ignore")
    pat='data-original="(.*?)1024.jpg!'
    imglist=re.compile(pat).findall(data)
    print(imglist)
    for j in range(0,len(imglist)):
         try:
             thisimgurl=imglist[j]
             thisurl=thisimgurl+"1024.jpg"
             file="C:/Users/tao/Desktop/python/20181129/pic/"+str(i)+str(j)+".jpg"
             urllib.request.urlretrieve(thisurl,filename= file)
             print("---成功--")
         except urllib.error.URLError as e:
                 if hasattr(e,"code"):
                    print(e.code)
                 if hasattr(e,"reason"):
                    print(e.reason)
         except Exception as e:
             print(e)


             
# demo 微信爬虫
#http://weixin.sogou.com/

import re
import urllib.request
import time
import urllib.error
import urllib.request
#自定义函数,功能为使用代理服务器爬一个网址
def use_proxy(proxy_addr,url):
    #建立异常处理机制
    try:
        req=urllib.request.Request(url)
        req.add_header('User-Agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.36 SE 2.X MetaSr 1.0')
        proxy= urllib.request.ProxyHandler({'http':proxy_addr})  
        opener = urllib.request.build_opener(proxy, urllib.request.HTTPHandler)  
        urllib.request.install_opener(opener)
        data = urllib.request.urlopen(req).read()
        return data
    except urllib.error.URLError as e:
        if hasattr(e,"code"):
            print(e.code)
        if hasattr(e,"reason"):
            print(e.reason)
        #若为URLError异常,延时10秒执行
        time.sleep(10)
    except Exception as e:
        print("exception:"+str(e))
        #若为Exception异常,延时1秒执行
        time.sleep(1)

#设置关键词            
key="Python"
#设置代理服务器,该代理服务器有可能失效,读者需要换成新的有效代理服务器
proxy="127.0.0.1:8888"
#爬多少页
for i in range(0,10):
    key=urllib.request.quote(key)
    thispageurl="http://weixin.sogou.com/weixin?type=2&query="+key+"&page="+str(i)
    #a="http://blog.csdn.net"
    thispagedata=use_proxy(proxy,thispageurl)
    print(len(str(thispagedata)))
    pat1='<a href="(.*?)"'
    rs1=re.compile(pat1,re.S).findall(str(thispagedata))
    if(len(rs1)==0):
        print("此次("+str(i)+"页)没成功")
        continue
    for  j in range(0,len(rs1)):
        thisurl=rs1[j]
        thisurl=thisurl.replace("amp;","")
        file="C:/Users/tao/Desktop/python/20181129/html/第"+str(i)+"页第"+str(j)+"篇文章.html"
       
        thisdata=use_proxy(proxy,thisurl)
        try:
            fh=open(file,"wb")
            fh.write(thisdata)
            fh.close()
            print("第"+str(i)+"页第"+str(j)+"篇文章成功")
        except Exception as e:
            print(e)
            print("第"+str(i)+"页第"+str(j)+"篇文章失败")



#demo 练习 爬虫评论


import urllib.request
import re
import urllib.error
headers=("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
comid="6165793094371986503"
url="http://video.coral.qq.com/filmreviewr/c/upcomment/0dfpyvfa7tp0ewe?commentid="+comid+"&reqnum=3&callback=jQuery1120026430801920245595_1478436999932&_=1478436999935"
for i in range(0,100):
    data=urllib.request.urlopen(url).read().decode()
    patnext='"last":"(.*?)"'
    nextid=re.compile(patnext).findall(data)[0]
    patcom='"content":"(.*?)",'
    comdata=re.compile(patcom).findall(data)
    for j in range(0,len(comdata)):
        print("------第"+str(i)+str(j)+"条评论内容是:")
        print(eval('u"'+comdata[j]+'"'))
    url="http://video.coral.qq.com/filmreviewr/c/upcomment/0dfpyvfa7tp0ewe?commentid="+nextid+"&reqnum=3&callback=jQuery1120026430801920245595_1478436999932&_=1478436999935"


# 多线程爬虫实战  , 可能有多行,用模式修正符re.S,可以点匹配换行。

import urllib.request
import re
import urllib.error
headers=("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)
for i in range(1,36):
    url="http://www.qiushibaike.com/8hr/page/"+str(i)
    pagedata=urllib.request.urlopen(url).read().decode("utf-8","ignore")
    pat='<div class="content">.*?<span>(.*?)</span>.*?</div>'
    datalist=re.compile(pat,re.S).findall(pagedata)
    for j in range(0,len(datalist)):
        print("第"+str(i)+"页第"+str(j)+"个段子的内容是:")
        print(datalist[j])

#Demo 多线程列子
        
import threading
class A(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        for i in range(0,10):
            print("我是线程A")
class B(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        for i in range(0,10):
            print("我是线程B")
t1=A()
t1.start()
t2=B()
t2.start()


# 多线程列子

import urllib.request
import threading
import re
import urllib.error
headers=("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.22 Safari/537.36 SE 2.X MetaSr 1.0")
opener=urllib.request.build_opener()
opener.addheaders=[headers]
urllib.request.install_opener(opener)

class One(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        for i in range(1,36,2):
            try:
                url="http://www.qiushibaike.com/8hr/page/"+str(i)
                pagedata=urllib.request.urlopen(url).read().decode("utf-8","ignore")
                pat='<div class="content">.*?<span>(.*?)</span>.*?</div>'
                datalist=re.compile(pat,re.S).findall(pagedata)
                for j in range(0,len(datalist)):
                    print("第"+str(i)+"页第"+str(j)+"个段子的内容是:")
                    print(datalist[j])
            except urllib.error.URLError as e:
                if hasattr(e,"code"):
                   print(e.code)
                if hasattr(e,"reason"):
                   print(e.reason)
            except Exception as e:
                print(e)        
class Two(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)
    def run(self):
        for i in range(0,36,2):
            try:
                url="http://www.qiushibaike.com/8hr/page/"+str(i)
                pagedata=urllib.request.urlopen(url).read().decode("utf-8","ignore")
                pat='<div class="content">.*?<span>(.*?)</span>.*?</div>'
                datalist=re.compile(pat,re.S).findall(pagedata)
                for j in range(0,len(datalist)):
                    print("第"+str(i)+"页第"+str(j)+"个段子的内容是:")
                    print(datalist[j])
            except urllib.error.URLError as e:
                if hasattr(e,"code"):
                   print(e.code)
                if hasattr(e,"reason"):
                   print(e.reason)
            except Exception as e:
                print(e)
one=One()
one.start()
two=Two()
two.start()    



# Scrapy安装

# pip install Scrapy
# pip install pypiwin32

#demo

from scrapy.spiders import Spider
class FirstSpider(Spider):
    name="p9"
    allowed_domains=["baidu.com"]
    # 初始网址
    start_urls=["http://www.baidu.com",]
    # 定义一个函数
    def parse(self,response):
        pass



#############常用命令#############
    
# cd  项目所在> scrapy runspider p9.py
# cd  C:\Users\tao\Desktop\python>scrapy runspider p9.py
    

# 创建项目
# scrapy startproject -h
# scrapy startproject <project_name>

# 运行爬虫一个文件
# scrapy crawl <project_name>

# 查看当前项目多个爬虫一个文件
# scrapy list


# scrapy version
# scrapy view http://news.sina.com 下载并打开网页
# scrapy bench  项目测试命令

# 进入项目后在输入   cd C:\Users\tao\Desktop\python\demo1\demo1>scrapy -h


# scrapy genspider -l  有哪些模板
# C:\Users\tao\Desktop\python\demo1\demo1> scrapy genspider -l 

Available templates:
  basic #表示 基本爬虫模板
  crawl #表示 自动爬虫模板
  csvfeed #表示 csv爬虫模板 主要处理csv文件
  xmlfeed #表示 xml爬虫模板 主要处理xml文件

  
# 创建项目
# scrapy startproject <project_name>                           模板名、爬虫名 、域名
# C:\Users\tao\Desktop\python\demo1\demo1> scrapy genspider -t basic tao baidu.com

# 执行
# scrapy crawl weixin --nolog


#
正则表达式
XPath表达式

/      表示一层一层的找
text() 表示提取标签下面的文本内容
@      表示提取标签属性的内容
//     表示寻找当前页所有标签
标签[@属性=值]
//li[@class="hidden-xs"]/a/@href

  
# demo 


python 运行文件的顺序
1、items.py 最先运行,首先创建容器,然后运行爬虫文件,查找网址如start_urls找到网址;
2、通过网址去请求request爬,爬了之后等到响应,响应服务器返回来得到信息网站的内容;
3、通过xpath表达式去提取,提取完,同时有两部分的信息,一部分是链接信息,一部分是提取出来的内容信息


#  习题及思考
#  demo json数据处理
import json
data='{"id":1234566,"name":"金子塔"}'
jdata=json.loads(data)
jdata.keys()
jdata["id"]

# demo 分布式思路
# 安装 命令 pip install scrapy-redis


# 项目练习
一 、首先到跟目录
scrapy startproject ts
cd ts
scrapy genspider -t basic hellobi hellobi.com

#运行命令
scrapy crawl hellobi --nolog



#自动模拟登陆爬虫实战



# 安装数据库
pip install pymysql



/usr/local/MySQL/bin/mysql -u root -p 

Root
123456

参考博客:https://blog.csdn.net/luohai859/article/details/50741496
设置mysql字符编码

/usr/local/MySQL/bin/mysql -u root -p 

Password:123456

查看:进入 mysql> show variables like '%char%';

my.cnf文件

[client]
default-character-set=utf8
 
[mysql]
default-character-set=utf8
 
[mysqld]
collation-server = utf8_unicode_ci
init-connect='SET NAMES utf8'
character-set-server = utf8
-------------------------------------
但是仍然没成功的时候,那么,重点来了,/etc/的路径应该是:cd /private/etc/
然后才是,新增一个 my.cnf 文件,然后写入命令保存退出,重启mysql
ps:如果无法保存,使用 sudo vim my.cnf



show variables like '%char%';


CREATE TABLE `books` (
  `t_id` int(11) NOT NULL AUTO_INCREMENT,
  `t_title` varchar(100) DEFAULT NULL,
  `t_link` varchar(100) DEFAULT NULL,
  `t_commentnums` varchar(100) DEFAULT NULL,
  `t_datetime` datetime DEFAULT NULL,
  PRIMARY KEY (`t_id`)
) ENGINE=InnoDB AUTO_INCREMENT=201 DEFAULT CHARSET=utf8;



CREATE TABLE `am_infomation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(100) DEFAULT NULL,
  `asin` varchar(100) DEFAULT NULL,
  `asingroup` varchar(100) DEFAULT NULL,
  `tags` varchar(100) DEFAULT NULL,
  `profile` varchar(100) DEFAULT NULL,
  `datetime` datetime DEFAULT NULL,
  `site` int(11) DEFAULT NULL,
  `votes` int(11) DEFAULT NULL,
  `ranking` varchar(100) DEFAULT NULL,
  `email` varchar(100) DEFAULT NULL,
  `facebook` varchar(100) DEFAULT NULL,
  `twitter` varchar(100) DEFAULT NULL,
  `youtube` varchar(100) DEFAULT NULL,
  `pinterest` varchar(100) DEFAULT NULL,
  `instagram` varchar(100) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;






一 、首先到跟目录
scrapy startproject amazon
cd amazon
scrapy genspider -t basic am amazon.com  # 基于basic 模板
scrapy genspider -t crawl am amazon.com  # 基于crawl 模板


#运行命令
scrapy crawl am --nolog

第①
第②
第③
第④
第⑤
第⑩ 数据分析与挖掘技术
一、概念
数据分析:对已知的数据进行分析,然后提取出一些有价值的信息;数据分析的数据量有可能不会太大;
数据挖掘:对大量的数据进行分析与挖掘,得到一些未知的、有价值的信息等;如:从网站的用户或用户行为数据中挖掘出用户的潜在需求信息,从而对网站进行改善;
数据分析与数据挖掘密不可分,数据挖掘是数据分析的提升;
二、做什么
数据挖掘技术可以帮助我们更好的发现事物之间的规律。
三、数据挖掘过程
1、定义目标

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ITdada

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值