jjzjj

Python网络爬虫 - 爬取中证网银行相关信息

HanaKoo 2023-03-28 原文

最终版:07_中证网(Plus -Pro).py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys
import os

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码

for qq in range(8):
    # query = input("【中证网】请输入你想搜索的内容:")
    query = '苏州银行'

    #年份
    year = [2014,2015,2016,2017,2018,2019,2020,2021]
    #总页数
    pages = [2,1,1,1,11,1,19,7]

    year = year[qq]
    pages = pages[qq]

    if not os.path.isdir(f'D:/桌面/爬虫-银行/中国证券网/{query}'):  # 如果没有此文件夹
        os.mkdir(f'D:/桌面/爬虫-银行/中国证券网/{query}')  # 创建此文件夹

    m = 0
    for p in range(1, pages + 1):
        url = f'http://search.cs.com.cn/search?page={p}&channelid=215308&searchword={query}&keyword={query}&token=12.1462412070719.47&perpage=10&outlinepage=5&&andsen=&total=&orsen=&exclude=&searchscope=&timescope=&timescopecolumn=&orderby=&timeline=={year}'

        dic = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

        resp = requests.get(url, headers=dic, )
        resp.encoding = 'utf-8'
        # print(resp)

        print(f'\n>>>--------------------第{p}页---------------------<<<\n')
        print(f'\n>>>--------------------第{p}页---------------------<<<\n')
        print(f'\n>>>--------------------第{p}页---------------------<<<\n')

        # print(resp.text)
        page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

        alist = page.find_all("table")
        datalist = []
        for ii in alist:
            ss=ii.find('td', style='font-size: 12px;line-height: 24px;color: #333333;margin-top: 4px;')
            # print('ss=\n\n',ss)
            if ss != None:
                ss = ss.get_text()
                datalist.append(ss)

        # print('data:',datalist,len(datalist))

        if not os.path.isdir(f'D:/桌面/爬虫-银行/中国证券网/{query}/{year}'):  # 如果没有此文件夹
            os.mkdir(f'D:/桌面/爬虫-银行/中国证券网/{query}/{year}')  # 创建此文件夹

        for ii in range(len(datalist)):
            fp = open(f'D:/桌面/爬虫-银行/中国证券网/{query}/{year}/({year}){ii + m + 1}.txt', 'w+', encoding='utf-8')
            fp.write(datalist[ii] + '\n')  # 只包含文本
            print(datalist[ii])
            print(f'\n> > >{year}年,第{p}页,第{ii + 1}篇,成功! < < <')
            fp.close()
        m = m + len(datalist) + 1

print('----------------------------')
print(f'------\n{year}年,爬取完毕----')
print('----------------------------')

历史优化记录:01_中证网.py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码


query = input("【中证网】请输入你想搜索的内容:")
pages = int(input("要爬取的页数(不小于1):"))
if pages < 1:
    exit()

url = f'http://search.cs.com.cn/search?channelid=215308&perpage=&templet=&token=12.1462412070719.47&searchword={query}'

dic = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
                  "Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"}

resp = requests.get(url, headers=dic, )
resp.encoding = 'utf-8'
# print(resp)

# print(resp.text)
page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

alist = page.find("table").find_all("a")

# print(alist)

weblist = []
for a in alist:
    if a.get('href')[:5] == "https":
        weblist.append(a.get('href'))

# ----------------单页每个文章---------------------------------
m = 0

for ii in range(len(weblist)):

    url_a = weblist[ii]

    # print('0=',url_a)

    dic_a = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
                      "Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"}

    resp_a = requests.get(url_a, headers=dic_a, )
    resp_a.encoding = 'gbk'

    # print('New:\n',resp_a.text)

    page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

    # print('123:\n',page_a)

    page_b = page_a.find('section').find_all('p')

    # print(page_b)
    fp=open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/{ii+1}.txt','w+',encoding='utf-8')

    txt_list = []
    for txt_a in page_b:
        # print(txt_a.text)
        txt_list.append(txt_a.text)

    # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

    for i in range(len(txt_list)):
        fp.write(txt_list[i] + '\n')  # 只包含文本

    fp.close()
    print(f'>>{ii+1}成功!')
    m = ii+1

# +-+++-----------++++++++++-----多页------++++++++++++----------++++

if pages > 1:
    for p in range(pages):
        url_s = f"http://search.cs.com.cn/search?page={p+1}&channelid=215308&searchword={query}"

        resp = requests.get(url, headers=dic, )
        resp.encoding = 'utf-8'
        # print(resp)

        # print(resp.text)
        page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

        alist = page.find("table").find_all("a")

        # print(alist)

        weblist = []
        for a in alist:
            if a.get('href')[:5] == "https":
                weblist.append(a.get('href'))

        # ----------------单页每个文章---------------------------------

        for ii in range(len(weblist)):

            url_a = weblist[ii]

            # print('0=',url_a)

            dic_a = {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
                              "Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"}

            resp_a = requests.get(url_a, headers=dic_a, )
            resp_a.encoding = 'gbk'

            # print('New:\n',resp_a.text)

            page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

            # print('123:\n',page_a)

            page_b = page_a.find('section').find_all('p')

            # print(page_b)
            fp = open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/{ii + 1 + m}.txt', 'w+', encoding='utf-8')

            txt_list = []
            for txt_a in page_b:
                # print(txt_a.text)
                txt_list.append(txt_a.text)

            # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

            for i in range(len(txt_list)):
                fp.write(txt_list[i] + '\n')  # 只包含文本

            print(f'>>{ii + 1 + m}成功!')
            m = m + ii + 1


fp.close()

print('---------------\n>>>爬取完毕<<<')

历史优化记录:02_中证网.py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码


query = input("【中证网】请输入你想搜索的内容:")
pages = int(input("要爬取的页数(不小于1):"))
if pages < 1:
    exit()

url = f'http://search.cs.com.cn/search?page=1&channelid=215308&searchword={query}'

dic = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
                  "Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"}

resp = requests.get(url, headers=dic, )
resp.encoding = 'utf-8'
# print(resp)

# print(resp.text)
page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

alist = page.find("table").find_all("a")

# print(alist)

weblist = []
for a in alist:
    if a.get('href')[:5] == "https":
        weblist.append(a.get('href'))

# ----------------单页每个文章---------------------------------
m = 0

for ii in range(len(weblist)):

    url_a = weblist[ii]

    # print('0=',url_a)

    dic_a = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
                      "Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"}

    resp_a = requests.get(url_a, headers=dic_a, )
    resp_a.encoding = 'gbk'

    # print('New:\n',resp_a.text)

    page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

    # print('123:\n',page_a)

    page_b = page_a.find('section').find_all('p')

    # print(page_b)
    fp=open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/0/(2021){ii+1}.txt','w+',encoding='utf-8')

    txt_list = []
    for txt_a in page_b:
        # print(txt_a.text)
        txt_list.append(txt_a.text)

    # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

    for i in range(len(txt_list)):
        fp.write(txt_list[i] + '\n')  # 只包含文本

    fp.close()
    print(f'>>{ii+1}成功!')
    m = ii+1

# +-+++-----------++++++++++-----多页------++++++++++++----------++++
# +-+++-----------++++++++++-----多页------++++++++++++----------++++

if pages > 1:
    for p in range(pages):
        url_s = f"http://search.cs.com.cn/search?page={p+1}&channelid=215308&searchword={query}"

        resp = requests.get(url, headers=dic, )
        resp.encoding = 'utf-8'
        # print(resp)

        # print(resp.text)
        page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

        alist = page.find("table").find_all("a")

        # print(alist)

        weblist = []
        for a in alist:
            if a.get('href')[:5] == "https":
                weblist.append(a.get('href'))

        # ----------------单页每个文章---------------------------------

        for ii in range(len(weblist)):

            url_a = weblist[ii]

            # print('0=',url_a)

            dic_a = {
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 "
                              "Safari/537.36 SLBrowser/7.0.0.6241 SLBChan/30"}

            resp_a = requests.get(url_a, headers=dic_a, )
            resp_a.encoding = 'gbk'

            # print('New:\n',resp_a.text)

            page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

            # print('123:\n',page_a)

            page_b = page_a.find('section').find_all('p')

            # print(page_b)
            fp = open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/0/(2021){ii + 1 + m}.txt', 'w+', encoding='utf-8')

            txt_list = []
            for txt_a in page_b:
                # print(txt_a.text)
                txt_list.append(txt_a.text)

            # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

            for i in range(len(txt_list)):
                fp.write(txt_list[i] + '\n')  # 只包含文本

            print(f'>>{ii + 1 + m}成功!')
        m = m + ii + 1


fp.close()

print('---------------\n>>>爬取完毕<<<')

历史优化记录:03_中证网.py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码

query = input("【中证网】请输入你想搜索的内容:")
pages = int(input("要爬取的页数(不小于1):"))
if pages < 1:
    exit()

m = 0
for p in range(1,pages+1):
    url = f'http://search.cs.com.cn/search?page={p}&channelid=215308&searchword={query}&perpage=10&outlinepage=5&&andsen=&total=&orsen=&exclude=&searchscope=&timescope=&timescopecolumn=&orderby=&timeline==2021'

    dic = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

    resp = requests.get(url, headers=dic, )
    resp.encoding = 'utf-8'
    # print(resp)

    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')

    # print(resp.text)
    page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

    alist = page.find("table").find_all('a')

    weblist = []

    for a in alist:
        if a.get('href')[:5] == "https":
            weblist.append(a.get('href'))
    # print('weblist==',weblist)
# ----------------单页每个文章---------------------------------

    for ii in range(len(weblist)):

        url_a = weblist[ii]

        # print('0=',url_a)

        dic_a = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

        resp_a = requests.get(url_a, headers=dic_a, )
        resp_a.encoding = 'gbk'

        # print('New:\n',resp_a.text)

        page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

        # print('123:\n',page_a)

        page_b = page_a.find('section').find_all('p')

        # print(page_b)
        fp=open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/2021/(2021){ii+m+1}.txt','w+',encoding='utf-8')

        txt_list = []
        for txt_a in page_b:
            # print('txt_a===',txt_a.text)
            txt_list.append(txt_a.text)
        print(f'\n-++++++++++++++++++第{ii+1}篇文章++++++++++++++++-\n',txt_list,len(txt_list))
        # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

        for i in range(len(txt_list)):
            fp.write(txt_list[i] + '\n')  # 只包含文本

        # print('-----------------------------------')
        print(f'\n> > >{ii+1}成功! < < <')
        fp.close()
    m=m+len(weblist)+1


print('---------------\n>>>爬取完毕<<<')

历史优化记录:04_中证网(网址筛选问题).py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码

query = input("【中证网】请输入你想搜索的内容:")
pages = int(input("要爬取的页数(不小于1):"))
if pages < 1:
    exit()

m = 0
for p in range(1,pages+1):
    url = f'http://search.cs.com.cn/search?page={pages}&channelid=215308&searchword={query}&keyword={query}&token=12.1462412070719.47&perpage=10&outlinepage=5&&andsen=&total=&orsen=&exclude=&searchscope=&timescope=&timescopecolumn=&orderby=&timeline==2020'

    dic = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

    resp = requests.get(url, headers=dic, )
    resp.encoding = 'utf-8'
    # print(resp)

    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')

    # print(resp.text)
    page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

    alist = page.find("table").find_all('a')

    print('alist:',alist)

    weblist = []

    for a in alist:
        if a.get('href')[4:] == "http":
            weblist.append(a.get('href'))

    print('weblist==',weblist)

# ----------------单页每个文章---------------------------------

    for ii in range(len(weblist)):

        url_a = weblist[ii]

        # print('0=',url_a)

        dic_a = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

        resp_a = requests.get(url_a, headers=dic_a, )
        resp_a.encoding = 'gbk'

        # print('New:\n',resp_a.text)

        page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

        # print('123:\n',page_a)

        page_b = page_a.find('section').find_all('p')

        # print(page_b)
        fp=open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/2020/(2020){ii+m+1}.txt','w+',encoding='utf-8')

        txt_list = []
        for txt_a in page_b:
            # print('txt_a===',txt_a.text)
            txt_list.append(txt_a.text)
        print(f'\n-++++++++++++++++++第{ii+1}篇文章++++++++++++++++-\n',txt_list,len(txt_list))
        # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

        for i in range(len(txt_list)):
            fp.write(txt_list[i] + '\n')  # 只包含文本

        # print('-----------------------------------')
        print(f'\n> > >{ii+1}成功! < < <')
        fp.close()
    m=m+len(weblist)+1


print('---------------\n>>>爬取完毕<<<')

历史优化记录:05_中证网.py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码

query = input("【中证网】请输入你想搜索的内容:")
year = int(input('要爬取的年份:'))
pages = int(input("要爬取的页数(不小于1):"))

if pages < 1:
    exit()

m = 0
for p in range(1, pages + 1):
    url = f'http://search.cs.com.cn/search?page={p}&channelid=215308&searchword={query}&keyword={query}&token=12.1462412070719.47&perpage=10&outlinepage=5&&andsen=&total=&orsen=&exclude=&searchscope=&timescope=&timescopecolumn=&orderby=&timeline=={year}'

    dic = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

    resp = requests.get(url, headers=dic, )
    resp.encoding = 'utf-8'
    # print(resp)

    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')

    # print(resp.text)
    page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

    alist = page.find("table").find('tr').find_all('a')

    # print('alist:', alist)

    weblist = []

    for a in alist:
        if a.get('href')[:4] == "http":
            weblist.append(a.get('href'))

    print('weblist==', weblist)

    # ----------------单页每个文章---------------------------------

    for ii in range(len(weblist)):

        url_a = weblist[ii]

        # print('0=',url_a)

        dic_a = {
            "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

        resp_a = requests.get(url_a, headers=dic_a, )
        resp_a.encoding = 'gbk'

        # print('New:\n',resp_a.text)

        page_a = BeautifulSoup(resp_a.text, "html.parser")  # 指定html解析器

        # print('123:\n',page_a)

        page_b = page_a.find_all('p')

        # print(page_b)
        fp = open(f'D:/桌面/爬虫-银行/中国证券网/中国银行/{year}/({year}){ii + m + 1}.txt', 'w+', encoding='utf-8')

        txt_list = []
        for txt_a in page_b:
            # print('txt_a===',txt_a.text)
            txt_list.append(txt_a.text)
        print(f'\n-++++++++++++++++++第{ii + 1}篇文章++++++++++++++++-\n', txt_list, len(txt_list))
        # +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        # ++++++++++++++++++++++文本写入+++++++++++++++++++++++++++++++

        for i in range(len(txt_list)):
            fp.write(txt_list[i] + '\n')  # 只包含文本

        # print('-----------------------------------')
        print(f'\n> > >{ii + 1}成功! < < <')
        fp.close()
    m = m + len(weblist) + 1

print('---------------\n>>>爬取完毕<<<')

历史优化记录:06_中证网(Plus).py

# coding=utf-8
import requests
from bs4 import BeautifulSoup
import io
import sys
import os

sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='gb18030')  # 改变标准输出的默认编码

# query = input("【中证网】请输入你想搜索的内容:")
query = '交通银行'
year = int(input('要爬取的年份:'))
pages = int(input("要爬取的页数(不小于1):"))

if pages < 1:
    exit()

m = 0
for p in range(1, pages + 1):
    url = f'http://search.cs.com.cn/search?page={p}&channelid=215308&searchword={query}&keyword={query}&token=12.1462412070719.47&perpage=10&outlinepage=5&&andsen=&total=&orsen=&exclude=&searchscope=&timescope=&timescopecolumn=&orderby=&timeline=={year}'

    dic = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36"}

    resp = requests.get(url, headers=dic, )
    resp.encoding = 'utf-8'
    # print(resp)

    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')
    print(f'\n>>>--------------------第{p}页---------------------<<<\n')

    # print(resp.text)
    page = BeautifulSoup(resp.text, "html.parser")  # 指定html解析器

    alist = page.find_all("table")
    datalist = []
    for ii in alist:
        ss=ii.find('td', style='font-size: 12px;line-height: 24px;color: #333333;margin-top: 4px;')
        # print('ss=\n\n',ss)
        if ss != None:
            ss = ss.get_text()
            datalist.append(ss)

    # print('data:',datalist,len(datalist))

    if not os.path.isdir(f'D:/桌面/爬虫-银行/中国证券网/{query}/{year}'):  # 如果没有此文件夹
        os.mkdir(f'D:/桌面/爬虫-银行/中国证券网/{query}/{year}')  # 创建此文件夹

    for ii in range(len(datalist)):
        fp = open(f'D:/桌面/爬虫-银行/中国证券网/{query}/{year}/({year}){ii + m + 1}.txt', 'w+', encoding='utf-8')
        fp.write(datalist[ii] + '\n')  # 只包含文本
        print(datalist[ii])
        print(f'\n> > >第{p}页,第{ii + 1}篇,成功! < < <')
        fp.close()
    m = m + len(datalist) + 1

print('----------------------------')
print(f'------\n{year}年,爬取完毕----')
print('----------------------------')

 

转载请注明出处,谢谢!!!

有关Python网络爬虫 - 爬取中证网银行相关信息的更多相关文章

  1. python - 如何使用 Ruby 或 Python 创建一系列高音调和低音调的蜂鸣声? - 2

    关闭。这个问题是opinion-based.它目前不接受答案。想要改进这个问题?更新问题,以便editingthispost可以用事实和引用来回答它.关闭4年前。Improvethisquestion我想在固定时间创建一系列低音和高音调的哔哔声。例如:在150毫秒时发出高音调的蜂鸣声在151毫秒时发出低音调的蜂鸣声200毫秒时发出低音调的蜂鸣声250毫秒的高音调蜂鸣声有没有办法在Ruby或Python中做到这一点?我真的不在乎输出编码是什么(.wav、.mp3、.ogg等等),但我确实想创建一个输出文件。

  2. ruby-on-rails - Rails 常用字符串(用于通知和错误信息等) - 2

    大约一年前,我决定确保每个包含非唯一文本的Flash通知都将从模块中的方法中获取文本。我这样做的最初原因是为了避免一遍又一遍地输入相同的字符串。如果我想更改措辞,我可以在一个地方轻松完成,而且一遍又一遍地重复同一件事而出现拼写错误的可能性也会降低。我最终得到的是这样的:moduleMessagesdefformat_error_messages(errors)errors.map{|attribute,message|"Error:#{attribute.to_s.titleize}#{message}."}enddeferror_message_could_not_find(obje

  3. ruby - 解析 RDFa、微数据等的最佳方式是什么,使用统一的模式/词汇(例如 schema.org)存储和显示信息 - 2

    我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i

  4. ruby-on-rails - 相关表上的范围为 "WHERE ... LIKE" - 2

    我正在尝试从Postgresql表(table1)中获取数据,该表由另一个相关表(property)的字段(table2)过滤。在纯SQL中,我会这样编写查询:SELECT*FROMtable1JOINtable2USING(table2_id)WHEREtable2.propertyLIKE'query%'这工作正常:scope:my_scope,->(query){includes(:table2).where("table2.property":query)}但我真正需要的是使用LIKE运算符进行过滤,而不是严格相等。然而,这是行不通的:scope:my_scope,->(que

  5. ruby - 用 Ruby 编写一个简单的网络服务器 - 2

    我想在Ruby中创建一个用于开发目的的极其简单的Web服务器(不,不想使用现成的解决方案)。代码如下:#!/usr/bin/rubyrequire'socket'server=TCPServer.new('127.0.0.1',8080)whileconnection=server.acceptheaders=[]length=0whileline=connection.getsheaders想法是从命令行运行这个脚本,提供另一个脚本,它将在其标准输入上获取请求,并在其标准输出上返回完整的响应。到目前为止一切顺利,但事实证明这真的很脆弱,因为它在第二个请求上中断并出现错误:/usr/b

  6. Python 相当于 Perl/Ruby ||= - 2

    这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:Pythonconditionalassignmentoperator对于这样一个简单的问题表示歉意,但是谷歌搜索||=并不是很有帮助;)Python中是否有与Ruby和Perl中的||=语句等效的语句?例如:foo="hey"foo||="what"#assignfooifit'sundefined#fooisstill"hey"bar||="yeah"#baris"yeah"另外,类似这样的东西的通用术语是什么?条件分配是我的第一个猜测,但Wikipediapage跟我想的不太一样。

  7. java - 什么相当于 ruby​​ 的 rack 或 python 的 Java wsgi? - 2

    什么是ruby​​的rack或python的Java的wsgi?还有一个路由库。 最佳答案 来自Python标准PEP333:Bycontrast,althoughJavahasjustasmanywebapplicationframeworksavailable,Java's"servlet"APImakesitpossibleforapplicationswrittenwithanyJavawebapplicationframeworktoruninanywebserverthatsupportstheservletAPI.ht

  8. 华为OD机试用Python实现 -【明明的随机数】 2023Q1A - 2

    华为OD机试题本篇题目:明明的随机数题目输入描述输出描述:示例1输入输出说明代码编写思路最近更新的博客华为od2023|什么是华为od,od薪资待遇,od机试题清单华为OD机试真题大全,用Python解华为机试题|机试宝典【华为OD机试】全流程解析+经验分享,题型分享,防作弊指南华为o

  9. 【鸿蒙应用开发系列】- 获取系统设备信息以及版本API兼容调用方式 - 2

    在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList​()Obt

  10. python - 如何读取 MIDI 文件、更改其乐器并将其写回? - 2

    我想解析一个已经存在的.mid文件,改变它的乐器,例如从“acousticgrandpiano”到“violin”,然后将它保存回去或作为另一个.mid文件。根据我在文档中看到的内容,该乐器通过program_change或patch_change指令进行了更改,但我找不到任何在已经存在的MIDI文件中执行此操作的库.他们似乎都只支持从头开始创建的MIDI文件。 最佳答案 MIDIpackage会为您完成此操作,但具体方法取决于midi文件的原始内容。一个MIDI文件由一个或多个音轨组成,每个音轨是十六个channel中任何一个上的

随机推荐