爬取下来的网页命名为wb_data,为什么wb_data.text与网页源代码内容不一样?

问题如题,我是小白,我看视频里面老师通过‘检查元素’定位元素在源代码中的位置,然后根据代码标签写selector,写代码,一运行就能得到想要的标签元素。我照着模仿,为什么结果为空,我最后发现我的wb_data.text与网页源代码有差别,我就想知道,为什么不一样?为什么视频中老师好像不会有这样的问题?下面是我的过程。
1. 我先打开要爬取的网页
2. 找到目标,点击检查元素定位其在网页代码中的位置
3. 观察,写selector
图片说明

  1. 写代码
from bs4 import BeautifulSoup
import requests

url = 'http://www.gov.cn/'
wb_data = requests.get(url)
soup = BeautifulSoup(wb_data.text, 'lxml')
title = soup.select('div.footer-all > ul.footer-two > li > a')
print(title)

最后结果:

图片说明

希望有大佬帮忙解答下,谢谢。

1个回答

import requests
import re
from lxml import etree

url = 'http://www.gov.cn/'
wb_data = requests.get(url)
title = ''.join(re.findall(r'(.*)',wb_data.content.decode('utf-8')))
print(title)

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
selenium单元测试用例调用不了,提示<unittest.suite.TestSuite tests=[<unittest.suite.TestSuite tests=[<unittest.loader._FailedTest testMethod=test_login>]>]>,只执行登录文件没有问题

错误日志如下 ![图片说明](https://img-ask.csdn.net/upload/202004/02/1585818429_774831.png) ``` test_login代码如下: from time import sleep import unittest import random, sys sys.path.append('test_case/models') sys.path.append('test_case/page_obj') from .models import myunit, function from .page_obj.loginPage import login class TestLogin(myunit.MyTest): '''社区登录测试''' # 测试用户登录 def user_login_verify(self, username, password): login(self.driver).user_login(username, password) def test_login(self): '''用户名密码正确''' self.user_login_verify("cs", "Cs88888") sleep(2) po = login(self.driver) self.assertEqual(po.user_login_success(), "消防管理信息系统") function.insert_img(self.driver, "user_pawd_ture.jpg") if __name__ == "__main__": unittest.main() ``` ``` 主文件如下 from HTMLTestRunner import HTMLTestRunner from email.mime.text import MIMEText from email.header import Header import smtplib import unittest import time import os if __name__ == '__main__': fp = open('./bbs/report/result.html', 'wb') # 创建测试报告,以写的方式存入某个路径 runner = HTMLTestRunner(stream=fp, title="测试报告", description="用例执行情况:") test_dir = 'D:/mztestpro/bbs/test_case' discover = unittest.defaultTestLoader.discover(test_dir, pattern='test_*.py') runner.run(discover) fp.close() ```

爬取子类型名称 并 实现跳转到子类型的网页

Hi 大家好啊: 我在写一个挖掘 “某网站上产品价格” 的程序。 之前在各路高手的帮助下,已经能捕捉到同一型号下 不同子型号的功能了 如 下面2张图片这样: (获取网页中 某类型产品 下 4个不同的子类型 名称信息) ![图片说明](https://img-ask.csdn.net/upload/201909/18/1568784373_803840.png) (返回值如下:) ![图片说明](https://img-ask.csdn.net/upload/201909/18/1568784498_31047.png) 目前,我的代码是这样的: ``` from bs4 import BeautifulSoup import requests url='https://www.lenovo.com/au/en/search?text=M720' # 这个是搜索 M720 时候的 返回网站 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'} # ok 至少 header 是没有问题的,可以进得去 def get_machine_infro(): wb_data = requests.get(url,headers=headers) #使用 url 和 header 打开网页 soup=BeautifulSoup(wb_data.text,'lxml') machin=soup.select('.o-productCard__content h3 a') # 网页源代码 机型处 前面的 网页码 注意 这个要选择那个唯一的 #machin=soup.select('.o-productCard__content') for i in range(len(machin)): print(machin[i].text) # 打印处 网页中全部的 机型名称 get_machine_infro() ``` 现在 我想更进一步: 去分别查看这些“子型号”产品下面的具体信息。 也许,可以是类似我们通过点击“Learn more” 按钮所实现的那种跳转(如下面的图片), 或者其他的方法...? ![图片说明](https://img-ask.csdn.net/upload/201909/18/1568784673_175671.png) 请问 要实现这种 针对 代码中已经获取的这些“子类型“跳转到相应的子页面的功能 我们应该如何实现呢? 谢谢各位大佬不吝赐教

PHP调整HTTP_RAW_POST_DATA的大小以保存图像

<div class="post-text" itemprop="text"> <p>How do I get a HTTP_RAW_POST_DATA and can resize to create a smaller image. With the image saved to disk I have classes that does this, more to get HTTP_RAW_POST_DATA I do not know how to do</p> <pre><code> if ( isset ( $GLOBALS["HTTP_RAW_POST_DATA"] )) { //the image file name $fileName = $_GET['nome'].".jpg"; // get the binary stream $im = $GLOBALS["HTTP_RAW_POST_DATA"]; //write it $fp = fopen('saves/print/'.$fileName, 'wb'); fwrite($fp, $im); fclose($fp); } </code></pre> </div>

为啥在jupyter运行没有结果

from bs4 import BeautifulSoup import requests import time headers={ 'Uster-Agent':'Mozilla/5.0(Windows NT 6.1;WOW64) AppleWebKit/537.36(KHTML,like Gecko) Cheom/53.0.2785.143 Safri/537.6' } def judgment_sex(class_name): if class_name ==['member_icol']: return '女' else: return '男' def get_links(url): wb_data =requests.get(url,headers=headers) soup= BeautifulSoup (wb_data.text,'lxml') links=soup.select('#page_list>ul>li>a') for link in links: href =link.get("href") get_info(href) def get_info (url): wb_data=requests.get(url,headers=headers) soup=BeautifulSoup(wb_data.texr,'lxml') titles=soup.select('div.pho_info>h4') addresses=soup.select('span.pro5') prices=soup.select('#pricePart>div.day_1>span') imgs=soup.select('#floatRightBox>div.js>box.clearfix>div.member_pic>a>img') names=soup.select('#floatRightBox>div.js_box.clearfix>div.w240>h6>a') sex.soup.select('#floatRightBox>div.js_box.clearfix>div.member_pic>div') for tittle, address, price, img, name, sex in zip(tittle,addresses,prices,imgs,names,sexs): data={ 'tittle':tittle.get_text().strip, 'address':address.get_text().strip(), 'price':price.get_text(), 'img':img.get("src"), 'name':name.get_text(), 'sex':judgment_sex(sex.get("clas")) } print(data) if __name__ == '__main__': urls=['http://bj.xiaozhu.com/search-duanzufang-p{}-0/'.format(number)for number in range (1,14)] for single_url in urls: get_links(single_url) time.sleep(4)

too long

<div class="post-text" itemprop="text"> <p>I have been testing an app i am writing in Monodroid(Mono for android). Basically i am storing some simple data to the database via a php post (http:// [my-domain]/register_php?/usrname=blabla&amp;usremail=blabla) (I am using thre free web hosting service 000webhost.com.)</p> <p>The php page sends back a response a simple string if it has succeded</p> <pre><code>&lt;?php (...) if( $success ) { echo "Success"; }else{ echo "Failure"; } &gt; </code></pre> <p>But in my android app I don't receive this simple string back as the answer. Rather I receive a full html page advertising the services 000webhost.com offers. <strong>But if i enter the url into my chrome browser every thing works fine and I receive the appropriate status (weither it has succeeded or not)</strong></p> <p>Here is the code to post data:</p> <pre><code>byte[] post_data = Encoding.ASCII.GetBytes(string.Format("name={0}&amp;email= {1}",txt_usr_name.Text,txt_usr_email .Text) ); HttpWebRequest wb_request = (HttpWebRequest )WebRequest.Create("http://[my-domain]/register_user.php" ); wb_request.Method = "POST"; wb_request.ContentType = "application/x-www-form-urlencoded"; wb_request.ContentLength = post_data.Length; Stream stream = wb_request.GetRequestStream(); stream.Write( post_data, 0, post_data.Length ); stream.Close(); </code></pre> <p>And here is the code to read back the response:</p> <pre><code> HttpWebResponse wb_response = ( HttpWebResponse )wb_request.GetResponse(); string status_code = wb_response.StatusCode.ToString(); string server = wb_response.Server.ToString(); Stream answer = wb_response.GetResponseStream(); StreamReader ans_reader = new StreamReader( answer ); string result = ans_reader.ReadToEnd(); AlertDialog.Builder builder = new AlertDialog.Builder( this ); builder.SetTitle( "Connection result" ); builder.SetMessage( result ); builder.SetPositiveButton( "OK", delegate { } ); var dialog = builder.Create(); dialog.Show(); </code></pre> <p>Is there something I am forgetting to set when i call the webservice? Thank you very much for your help</p> </div>

openpyxl.load__workbook(filename)报错ValueError: Max value is 52

openpyxl.load__workbook(filename)报错ValueError: Max value is 52,但是只有个别表格会出现报错,什么原因? ``` import openpyxl filename="测试2.xlsx"#读取excel workbook=openpyxl.load_workbook(filename,data_only=True) worksheet=workbook.get_sheet_by_name("Sheet1") ``` 报错信息如下: ``` File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\reader\excel.py", line 314, in load_workbook reader.read() File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\reader\excel.py", line 279, in read self.read_worksheets() File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\reader\excel.py", line 254, in read_worksheets charts, images = find_images(self.archive, rel.target) File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\reader\drawings.py", line 27, in find_images drawing = SpreadsheetDrawing.from_tree(tree) File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree obj = desc.expected_type.from_tree(el) File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree obj = desc.expected_type.from_tree(el) File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\descriptors\serialisable.py", line 87, in from_tree obj = desc.expected_type.from_tree(el) [Previous line repeated 3 more times] File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\descriptors\serialisable.py", line 103, in from_tree return cls(**attrib) File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\drawing\text.py", line 115, in __init__ self.pitchFamily = pitchFamily File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\descriptors\base.py", line 108, in __set__ super(Min, self).__set__(instance, value) File "C:\Users\mayn\AppData\Local\Programs\Python\Python36\lib\site-packages\openpyxl\descriptors\base.py", line 87, in __set__ raise ValueError('Max value is {0}'.format(self.max)) ValueError: Max value is 52 ```

python scrapy 爬虫图片新手求助

求问大神 我这个data她怎么了 报错: 2020-02-07 09:24:55 [scrapy.utils.log] INFO: Scrapy 1.8.0 started (bot: meizitu) 2020-02-07 09:24:55 [scrapy.utils.log] INFO: Versions: lxml 4.5.0.0, libxml2 2.9.5, cssselect 1.1.0, parsel 1.5.2, w3lib 1.21.0, Twisted 19.10.0, Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)], pyOpenSSL 19.1.0 (OpenSSL 1.1.1d 10 Sep 2019), cryptography 2.8, Platform Windows-10-10.0.17763-SP0 2020-02-07 09:24:55 [scrapy.crawler] INFO: Overridden settings: {'BOT_NAME': 'meizitu', 'NEWSPIDER_MODULE': 'meizitu.spiders', 'ROBOTSTXT_OBEY': True, 'SPIDER_MODULES': ['meizitu.spiders']} 2020-02-07 09:24:55 [scrapy.extensions.telnet] INFO: Telnet Password: 0936097982b9bcc8 2020-02-07 09:24:55 [scrapy.middleware] INFO: Enabled extensions: ['scrapy.extensions.corestats.CoreStats', 'scrapy.extensions.telnet.TelnetConsole', 'scrapy.extensions.logstats.LogStats'] 2020-02-07 09:24:56 [scrapy.middleware] INFO: Enabled downloader middlewares: ['scrapy.downloadermiddlewares.robotstxt.RobotsTxtMiddleware', 'scrapy.downloadermiddlewares.httpauth.HttpAuthMiddleware', 'scrapy.downloadermiddlewares.downloadtimeout.DownloadTimeoutMiddleware', 'scrapy.downloadermiddlewares.defaultheaders.DefaultHeadersMiddleware', 'scrapy.downloadermiddlewares.useragent.UserAgentMiddleware', 'scrapy.downloadermiddlewares.retry.RetryMiddleware', 'scrapy.downloadermiddlewares.redirect.MetaRefreshMiddleware', 'scrapy.downloadermiddlewares.httpcompression.HttpCompressionMiddleware', 'scrapy.downloadermiddlewares.redirect.RedirectMiddleware', 'scrapy.downloadermiddlewares.cookies.CookiesMiddleware', 'scrapy.downloadermiddlewares.httpproxy.HttpProxyMiddleware', 'scrapy.downloadermiddlewares.stats.DownloaderStats'] 2020-02-07 09:24:56 [scrapy.middleware] INFO: Enabled spider middlewares: ['scrapy.spidermiddlewares.httperror.HttpErrorMiddleware', 'scrapy.spidermiddlewares.offsite.OffsiteMiddleware', 'scrapy.spidermiddlewares.referer.RefererMiddleware', 'scrapy.spidermiddlewares.urllength.UrlLengthMiddleware', 'scrapy.spidermiddlewares.depth.DepthMiddleware'] Unhandled error in Deferred: 2020-02-07 09:24:56 [twisted] CRITICAL: Unhandled error in Deferred: Traceback (most recent call last): File "e:\python3.7\lib\site-packages\scrapy\crawler.py", line 184, in crawl return self._crawl(crawler, *args, **kwargs) File "e:\python3.7\lib\site-packages\scrapy\crawler.py", line 188, in _crawl d = crawler.crawl(*args, **kwargs) File "e:\python3.7\lib\site-packages\twisted\internet\defer.py", line 1613, in unwindGenerator return _cancellableInlineCallbacks(gen) File "e:\python3.7\lib\site-packages\twisted\internet\defer.py", line 1529, in _cancellableInlineCallbacks _inlineCallbacks(None, g, status) --- <exception caught here> --- File "e:\python3.7\lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks result = g.send(result) File "e:\python3.7\lib\site-packages\scrapy\crawler.py", line 86, in crawl self.engine = self._create_engine() File "e:\python3.7\lib\site-packages\scrapy\crawler.py", line 111, in _create_engine return ExecutionEngine(self, lambda _: self.stop()) File "e:\python3.7\lib\site-packages\scrapy\core\engine.py", line 70, in __init__ self.scraper = Scraper(crawler) File "e:\python3.7\lib\site-packages\scrapy\core\scraper.py", line 71, in __init__ self.itemproc = itemproc_cls.from_crawler(crawler) File "e:\python3.7\lib\site-packages\scrapy\middleware.py", line 53, in from_crawler return cls.from_settings(crawler.settings, crawler) File "e:\python3.7\lib\site-packages\scrapy\middleware.py", line 34, in from_settings mwcls = load_object(clspath) File "e:\python3.7\lib\site-packages\scrapy\utils\misc.py", line 46, in load_object mod = import_module(module) File "e:\python3.7\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 724, in exec_module File "<frozen importlib._bootstrap_external>", line 860, in get_code File "<frozen importlib._bootstrap_external>", line 791, in source_to_code File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed builtins.SyntaxError: unexpected EOF while parsing (pipelines.py, line 22) 2020-02-07 09:24:56 [twisted] CRITICAL: Traceback (most recent call last): File "e:\python3.7\lib\site-packages\twisted\internet\defer.py", line 1418, in _inlineCallbacks result = g.send(result) File "e:\python3.7\lib\site-packages\scrapy\crawler.py", line 86, in crawl self.engine = self._create_engine() File "e:\python3.7\lib\site-packages\scrapy\crawler.py", line 111, in _create_engine return ExecutionEngine(self, lambda _: self.stop()) File "e:\python3.7\lib\site-packages\scrapy\core\engine.py", line 70, in __init__ self.scraper = Scraper(crawler) File "e:\python3.7\lib\site-packages\scrapy\core\scraper.py", line 71, in __init__ self.itemproc = itemproc_cls.from_crawler(crawler) File "e:\python3.7\lib\site-packages\scrapy\middleware.py", line 53, in from_crawler return cls.from_settings(crawler.settings, crawler) File "e:\python3.7\lib\site-packages\scrapy\middleware.py", line 34, in from_settings mwcls = load_object(clspath) File "e:\python3.7\lib\site-packages\scrapy\utils\misc.py", line 46, in load_object mod = import_module(module) File "e:\python3.7\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 724, in exec_module File "<frozen importlib._bootstrap_external>", line 860, in get_code File "<frozen importlib._bootstrap_external>", line 791, in source_to_code File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "E:\python_work\爬虫\meizitu\meizitu\pipelines.py", line 22 f.write(data) ^ SyntaxError: unexpected EOF while parsing 代码如下: pipeline ``` import requests class MeizituPipeline(object): def process_item(self, item, spider): print("main_title:",item['main_title']) print("main_image:", item['main_image']) print("main_tags:", item['main_tags']) print("main_meta:", item['main_meta']) print("page:", item['main_pagenavi']) url = requests.get(item['main_image']) print(url) try: with open(item['main_pagenavi'] +'.jpg','wb') as f: data = url.read() f.write(data) ``` image.py ``` import scrapy from scrapy.http import response from ..items import MeizituItem class ImageSpider(scrapy.Spider): #定义Spider的名字scrapy crawl meiaitu name = 'SpiderMain' #允许爬虫的域名 allowed_domains = ['www.mzitu.com/203554'] #爬取的首页列表 start_urls = ['https://www.mzitu.com/203554'] #负责提取response的信息 #response代表下载器从start_urls中的url的到的回应 #提取的信息 def parse(self,response): #遍历所有节点 for Main in response.xpath('//div[@class = "main"]'): item = MeizituItem() #匹配所有节点元素/html/body/div[2]/div[1]/div[3]/p/a content = Main.xpath('//div[@class = "content"]') item['main_title'] = content.xpath('./h2/text()') item['main_image'] = content.xpath('./div[@class="main-image"]/p/a/img') item['main_meta'] = content.xpath('./div[@class="main-meta"]/span/text()').extract() item['main_tags'] = content.xpath('./div[@class="main-tags"]/a/text()').extract() item['main_pagenavi'] = content.xpath('./div[@class="main_pagenavi"]/span/text()').extract_first() yield item new_links = response.xpath('.//div[@class="pagenavi"]/a/@href').extract() new_link =new_links[-1] yield scrapy.Request(new_link,callback=self.parse) ``` setting ``` BOT_NAME = 'meizitu' SPIDER_MODULES = ['meizitu.spiders'] NEWSPIDER_MODULE = 'meizitu.spiders' ROBOTSTXT_OBEY = True #配置默认请求头 DEFAULT_REQUEST_HEADERS = { "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.108 Safari/537.36", 'Accept':'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8' } ITEM_PIPELINES = { 'meizitu.pipelines.MeizituPipeline':300, } IMAGES_STORE = 'E:\python_work\爬虫\meizitu' IMAGES_MIN_HEIGHT = 1050 IMAGES_MIN_WIDTH = 700 ```

python爬虫爬取的图片存在错误打不开

python3写的不知道哪里错了,求教大家帮看看 import requests from bs4 import BeautifulSoup ''' https://www.mzitu.com/ ''' def get_girls(url): headers = {'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" } Picreferer = {'User-Agent': "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36" } path = 'D:/mzitu/' html = requests.get(url,headers=headers).text all_list = BeautifulSoup(html,'lxml').find('ul',id="pins").find_all('li') for _ in all_list: girl_title = _.get_text() girl_url = _.find('img')['data-original'] print("{}:{}".format(girl_title,girl_url)) response = requests.get(girl_url,headers=headers) fileName = girl_title + '.jpg' print('正在保存图片' + fileName) with open(fileName,'wb') as f: f.write(response.content) if __name__ =="__main__": for page in range(1,229): url = 'https://www.mzitu.com/page/%s/' % page get_girls(url)

如何进行文件下载而不是保存在服务器上?

<div class="post-text" itemprop="text"> <pre><code> $filename = "PM.xls"; $exists = file_exists('PM.xls'); if($exists) { unlink($filename); } $filename = "PM.xls"; $fp = fopen($filename, "wb"); $sql = "SELECT DATE_FORMAT(jobcard.Open_date_time,' %d-%b-%y') AS datee,vehicles_data.Frame_no, jobcard.Jobc_id,jobcard.serv_nature,jobcard.Customer_name,jobc_invoice.Lnet, jobc_invoice.Pnet, jobc_invoice.Snet, jobcard.Mileage,customer_data.cust_type,vehicles_data.model_year,jobcard.Veh_reg_no,jobcard.comp_appointed, customer_data.mobile,IF(variant_codes.Make IS NULL,'Others',variant_codes.Make) as make FROM `jobcard` LEFT OUTER JOIN jobc_invoice ON jobcard.Jobc_id=jobc_invoice.Jobc_id LEFT OUTER JOIN vehicles_data ON jobcard.Vehicle_id=vehicles_data.Vehicle_id LEFT OUTER JOIN variant_codes ON vehicles_data.Model=variant_codes.Model LEFT OUTER JOIN customer_data ON jobcard.Customer_id=customer_data.Customer_id ORDER BY `make` ASC"; $result=mysqli_query($conn,$sql) or die(mysqli_error($sql)); $schema_insert = ""; $schema_insert_rows = ""; while($row = mysqli_fetch_row($result)) { $insert = $row[0]. "\t" .$row[1]. "\t".$row[2]. "\t".$row[3]. "\t".$row[4]. "\t".$row[5]. "\t".$row[6]. "\t".$row[7]. "\t".$row[8]. "\t".$row[9]. "\t".$row[10]. "\t".$row[11]. "\t".$row[12]. "\t".$row[13]. "\t".$row[14]. "\t".$row[15]; $insert .= " "; // serialize($assoc) fwrite($fp, $insert); } </code></pre> <p>Above code successfully creates the file on server but can't replace it, Instead of creating the file on server i want it download the file on user end. Should I use any excel library as I have to name excel sheet as well.</p> </div>

R语言中利用download.file时出现错误,求大神帮助!!!

url <- "http://drygin.ccbr.utoronto.ca/~costanzo2009/sgadata_costanzo2009_rawdata_101120.txt.gz" download.file(url, file.path("Data", "sgadata_costanzo2009_rawdata_101120.txt.gz"), method="curl 上面是程序运行后出现错误 Error in download.file(url, file.path("Data", "sgadata_costanzo2009_rawdata_101120.txt.gz"), : 'curl' call had nonzero exit status In addition: Warning message: running command 'curl "http://drygin.ccbr.utoronto.ca/~costanzo2009/sgadata_costanzo2009_rawdata_101120.txt.gz" -o "Data/sgadata_costanzo2009_rawdata_101120.txt.gz"' had status 127 这到底是怎么回事啊 求大神帮助

pycharm运行mnist_show.py出现如下问题,

# 这是深度学习入门这本书里的一段代码,请问这个问题是什么意思以及怎样解决? 报错如下:(下面有源代码)Python 3.7.3 (default, Mar 27 2019, 17:13:21) [MSC v.1915 64 bit (AMD64)] on win32 runfile('E:/PycharmProjects/deep-learning-from-scratch-master/ch03/mnist_show.py', wdir='E:/PycharmProjects/deep-learning-from-scratch-master/ch03') Converting train-images-idx3-ubyte.gz to NumPy Array ... Traceback (most recent call last): File "D:\Anaconda3\lib\site-packages\IPython\core\interactiveshell.py", line 3296, in run_code exec(code_obj, self.user_global_ns, self.user_ns) File "<ipython-input-2-eab209ee1d7f>", line 1, in <module> runfile('E:/PycharmProjects/deep-learning-from-scratch-master/ch03/mnist_show.py', wdir='E:/PycharmProjects/deep-learning-from-scratch-master/ch03') File "D:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "D:\Program Files\JetBrains\PyCharm 2019.1.1\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "E:/PycharmProjects/deep-learning-from-scratch-master/ch03/mnist_show.py", line 13, in <module> (x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False) File "E:\PycharmProjects\deep-learning-from-scratch-master\dataset\mnist.py", line 106, in load_mnist init_mnist() File "E:\PycharmProjects\deep-learning-from-scratch-master\dataset\mnist.py", line 76, in init_mnist dataset = _convert_numpy() 源代码为:# coding: utf-8 mnist_show.py:::: import sys, os sys.path.append(os.pardir) # 为了导入父目录的文件而进行的设定 import numpy as np from dataset.mnist import load_mnist from PIL import Image def img_show(img): pil_img = Image.fromarray(np.uint8(img)) pil_img.show() (x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False) img = x_train[0] label = t_train[0] print(label) # 5 print(img.shape) # (784,) img = img.reshape(28, 28) # 把图像的形状变为原来的尺寸 print(img.shape) # (28, 28) img_show(img) mnist.py::: # coding: utf-8 try: import urllib.request except ImportError: raise ImportError('You should use Python 3.x') import os.path import gzip import pickle import os import numpy as np url_base = 'http://yann.lecun.com/exdb/mnist/' key_file = { 'train_img':'train-images-idx3-ubyte.gz', 'train_label':'train-labels-idx1-ubyte.gz', 'test_img':'t10k-images-idx3-ubyte.gz', 'test_label':'t10k-labels-idx1-ubyte.gz' } dataset_dir = os.path.dirname(os.path.abspath(__file__)) save_file = dataset_dir + "/mnist.pkl" train_num = 60000 test_num = 10000 img_dim = (1, 28, 28) img_size = 784 def _download(file_name): file_path = dataset_dir + "/" + file_name if os.path.exists(file_path): return print("Downloading " + file_name + " ... ") urllib.request.urlretrieve(url_base + file_name, file_path) print("Done") def download_mnist(): for v in key_file.values(): _download(v) def _load_label(file_name): file_path = dataset_dir + "/" + file_name print("Converting " + file_name + " to NumPy Array ...") with gzip.open(file_path, 'rb') as f: labels = np.frombuffer(f.read(), np.uint8, offset=8) print("Done") return labels def _load_img(file_name): file_path = dataset_dir + "/" + file_name print("Converting " + file_name + " to NumPy Array ...") with gzip.open(file_path, 'rb') as f: data = np.frombuffer(f.read(), np.uint8, offset=16) data = data.reshape(-1, img_size) print("Done") return data def _convert_numpy(): dataset = {} dataset['train_img'] = _load_img(key_file['train_img']) dataset['train_label'] = _load_label(key_file['train_label']) dataset['test_img'] = _load_img(key_file['test_img']) dataset['test_label'] = _load_label(key_file['test_label']) return dataset def init_mnist(): download_mnist() dataset = _convert_numpy() print("Creating pickle file ...") with open(save_file, 'wb') as f: pickle.dump(dataset, f, -1) print("Done!") def _change_one_hot_label(X): T = np.zeros((X.size, 10)) for idx, row in enumerate(T): row[X[idx]] = 1 return T def load_mnist(normalize=True, flatten=True, one_hot_label=False): """读入MNIST数据集 Parameters ---------- normalize : 将图像的像素值正规化为0.0~1.0 one_hot_label : one_hot_label为True的情况下,标签作为one-hot数组返回 one-hot数组是指[0,0,1,0,0,0,0,0,0,0]这样的数组 flatten : 是否将图像展开为一维数组 Returns ------- (训练图像, 训练标签), (测试图像, 测试标签) """ if not os.path.exists(save_file): init_mnist() with open(save_file, 'rb') as f: dataset = pickle.load(f) if normalize: for key in ('train_img', 'test_img'): dataset[key] = dataset[key].astype(np.float32) dataset[key] /= 255.0 if one_hot_label: dataset['train_label'] = _change_one_hot_label(dataset['train_label']) dataset['test_label'] = _change_one_hot_label(dataset['test_label']) if not flatten: for key in ('train_img', 'test_img'): dataset[key] = dataset[key].reshape(-1, 1, 28, 28) return (dataset['train_img'], dataset['train_label']), (dataset['test_img'], dataset['test_label']) if __name__ == '__main__': init_mnist()

采用多线程爬取包情包,程序运行得不到预计的结果,求帮助

程序目的是采用多线程的方式,爬取斗图啦前100页的所有表情包。 我采用的是多线程的方式, 第一次运行的时候,程序能爬,但只爬取5页的表情包,程序就结束了。再次运行的时候,程序一直在运行,不停下来。我尝试过修改线程数,没有任何作用。 代码如下,希望有大佬,好心人,帮我看看程序出错在哪? ``` from urllib import request from queue import Queue from lxml import etree import threading import requests import time import re import os # 生产者模型 class Producer(threading.Thread): headers ={ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36" } # 实例方法,接受参数值 def __init__(self,page_queue,img_queue,*args,**kwargs): super(Producer,self).__init__(*args,**kwargs) self.page_queue = page_queue self.img_queue = img_queue def run(self): while True: if self.page_queue.empty(): # 退出循环调节为装url的队列全空 break url = self.page_queue.get() # 拿到url,进行解析 self.parse_page(url) def parse_page(self,url): response = requests.get(url,headers=self.headers,timeout=30) text = response.text html = etree.HTML(text) imgs = html.xpath('//div[@class="page-content text-center"]//img[@class!="gif"]') for img in imgs: img_url = img.get('data-original') alt = img.get('alt') alt = re.sub(r'[\??\.。!\*\!/:]','',alt) suffix = os.path.splitext(img_url)[1] filename = alt + suffix # 将得到信息传递给中间这,然后在给消费者 self.img_queue.put((img_url,filename)) # 文件信息给队列 # 消费者模型 class Consumer(threading.Thread): def __init__(self,page_queue,img_queue,*args,**kwargs): super(Consumer,self).__init__(*args,**kwargs) self.page_queue = page_queue self.img_queue = img_queue def run(self): while True: if self.img_queue.empty() and self.page_queue.empty(): break img_url, filename = self.img_queue.get() with open('F:/imgs/{}'.format(filename),'wb') as f: f.write(requests.get(img_url).content) print("{}".format(filename)) def main(): page_queue = Queue(100) #存储文件信息,包括url和文件名 img_queue = Queue(500) # 存储图片的队列 # 打印前100页的url,存入队列中 for i in range(1,101): url = 'http://www.doutula.com/photo/list/?page={}'.format(i) page_queue.put(url) # 添加url到队列中 # 开启5个生产者 for x in range(5): t = Producer(page_queue,img_queue) t.start() # 开启4个消费者 for x in range(4): t = Consumer(page_queue,img_queue) t.start() if __name__ == '__main__': main() __name__ == '__main__': main() ```

使用tensorflow的API dataset遇到memoryerror

使用Tensorflow的API dataset的时候遇到了memoryerror,可是我是使用官方推荐的占位符的方法啊,我的系统是ubuntu 18.0.4,tensorflow 的版本是1.13.1,Python3.6,先上代码: ``` def main(_): if FLAGS.self_test: train_data, train_labels = fake_data(256) validation_data, validation_labels = fake_data(EVAL_BATCH_SIZE) test_data, test_labels = fake_data(EVAL_BATCH_SIZE) num_epochs = 1 else: stft_training, mfcc_training, labels_training = joblib.load(open(FLAGS.input, mode='rb')) stft_training = numpy.array(stft_training) mfcc_training = numpy.array(mfcc_training) labels_training = numpy.array(labels_training) stft_shape = stft_training.shape stft_shape = (None, stft_shape[1], stft_shape[2]) mfcc_shape = mfcc_training.shape mfcc_shape = (None, mfcc_shape[1], mfcc_shape[2]) labels_shape = labels_training.shape labels_shape = (None) stft_placeholder = tf.placeholder(stft_training.dtype, stft_shape) labels_placeholder = tf.placeholder(labels_training.dtype, labels_shape) mfcc_placeholder = tf.placeholder(mfcc_training.dtype, mfcc_shape) dataset_training = tf.data.Dataset.from_tensor_slices((stft_placeholder, mfcc_placeholder, labels_placeholder)) dataset_training = dataset_training .apply( tf.data.experimental.shuffle_and_repeat(len(stft_training), None)) dataset_training = dataset_training .batch(BATCH_SIZE) dataset_training = dataset_training .prefetch(1) iterator_training = dataset_training.make_initializable_iterator() next_element_training = iterator_training.get_next() num_epochs = NUM_EPOCHS train_size = labels_training.shape[0] stft = tf.placeholder( data_type(), shape=(BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WEITH, NUM_CHANNELS)) mfcc = tf.placeholder( data_type(), shape=(BATCH_SIZE, IMAGE_HEIGHT, IMAGE_WEITH, NUM_CHANNELS)) labels = tf.placeholder(tf.int64, shape=(BATCH_SIZE,)) model = BRN(stft, mfcc) config = tf.ConfigProto() config.gpu_options.allow_growth = True with tf.Session(config=config) as sess: tf.global_variables_initializer().run() train_writer = tf.summary.FileWriter(log_dir + 'train', sess.graph) converter = tf.lite.TFLiteConverter.from_session(sess, [stft,mfcc], [logits]) tflite_model = converter.convert() open("BRN.tflite", "wb").write(tflite_model) print('Initialized!') sess.run(iterator_training.initializer, feed_dict={stft_placeholder:stft_training, mfcc_placeholder:stft_training, labels_placeholder:stft_training}) ``` 报错信息: ![图片说明](https://img-ask.csdn.net/upload/201907/21/1563699144_423650.png)

TypeError: a bytes-like object is required, not '_io.TextIOWrapper' 想把标签和图片变成pickle

报出这个错误,很是费解。。求大神解救 import tensorflow as tf import os import numpy as np from PIL import Image import pickle img_path='./flower_photos' img_size=224 def read_image(img_path): imgs=[] labels=[] num=0 for i in os.listdir(img_path): if os.path.isdir(os.path.join(img_path,i)): # print(i) for j in os.listdir(os.path.join(img_path,i)): path=os.path.join(img_path,i)+'/'+j # print(path) img=Image.open(path) img=img.resize((img_size,img_size)) img_ndarray=np.asarray(img,dtype='float32') imgs.append(np.ndarray.flatten(img_ndarray)) num+=1 if i=='daisy': labels.append(0) elif i=='dandelion': labels.append(1) elif i=='roses': labels.append(2) elif i=='sunflowers': labels.append(3) elif i=='tulips': labels.append(4) # print(imgs) # print(labels) # print('一共%d个图片',num) return imgs,labels,num def generate_imgpickle(img_path,outfile): write_file=open(outfile,'wb') imgs,labels,num=read_image(img_path) print(imgs,labels,num) pickle.dump(imgs[0:num],labels[0:num],write_file,-1) write_file.close() def load_imgpickle(outfile): reader=open(outfile) data=pickle.loads(reader) print(reader) reader.close() if __name__=='__main__': generate_imgpickle(img_path,'trainimg.pickle') load_imgpickle('trainimg.pickle')

openpyxl 生产xlsx文件报错

python 3.6 openpyxl 3.0.2 ```python from openpyxl import Workbook from openpyxl.utils import get_column_letter wb = Workbook() dest_filename = 'empty_book.xlsx' ws1 = wb.active ws1.title = "range names" for row in range(1, 40): ws1.append(range(600)) ws2 = wb.create_sheet(title="Pi") ws2['F5'] = 3.14 ws3 = wb.create_sheet(title="Data") for row in range(10, 20): for col in range(27, 54): _ = ws3.cell(column=col, row=row, value="{0}".format(get_column_letter(col))) print(ws3['AA10'].value) wb.save(filename = dest_filename) ``` Traceback (most recent call last): File "C:/Users/Administrator/Desktop/python 报价单生成脚本/111.py", line 36, in <module> wb.save(filename = dest_filename) File "D:\Anaconda3\lib\site-packages\openpyxl\workbook\workbook.py", line 408, in save save_workbook(self, filename) File "D:\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 293, in save_workbook writer.save() File "D:\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 275, in save self.write_data() File "D:\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 75, in write_data self._write_worksheets() File "D:\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 215, in _write_worksheets self.write_worksheet(ws) File "D:\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 200, in write_worksheet writer.write() File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet\_writer.py", line 354, in write self.write_top() File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet\_writer.py", line 98, in write_top self.write_properties() File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet\_writer.py", line 60, in write_properties self.xf.send(props.to_tree()) File "D:\Anaconda3\lib\site-packages\openpyxl\worksheet\_writer.py", line 294, in get_stream xf.write(el) File "src/lxml/serializer.pxi", line 1230, in lxml.etree._IncrementalFileWriter.write TypeError: got invalid input value of type <class 'xml.etree.ElementTree.Element'>, expected string or Element

使用Python 在excel指定单元格中写入指定单元格,但是在excel中不显示出来

各位大佬,咨询一个问题: 使用Python 提取数据库中数据 并录入excel 指定也签下的指定单元格。当前,操纵数据库,提取信息,等等步骤都没有问题,但是最后一步出问题了: 数据无法正常写入到excel中(excel中不显示) 如图: ![图片说明](https://img-ask.csdn.net/upload/201905/27/1558962156_379458.jpg) ![图片说明](https://img-ask.csdn.net/upload/201905/27/1558962181_372946.jpg) 以下是我的代码:求高手指点迷津,谢谢~ ``` import pymysql import tkinter import os import openpyxl from tkinter import * import time def newcreated(): ## 用来提取数据 conn = pymysql.connect(host='localhost',user='root',passwd='QAZwsx12345678',db='test',port=3306,charset='utf8') cur = conn.cursor() cur.execute("use test") cur.execute("SELECT SUM(sql_data.`总价`) FROM sql_data WHERE sql_data.`销售区域`= '东大区'") a = cur.fetchall() time.sleep(0.2) cur.execute("SELECT SUM(sql_data.`总价`) FROM sql_data WHERE sql_data.`销售区域`= '西大区'") b = cur.fetchall() time.sleep(0.2) cur.execute("SELECT SUM(sql_data.`总价`) FROM sql_data WHERE sql_data.`销售区域`= '南大区'") c = cur.fetchall() cur.execute("SELECT SUM(sql_data.`总价`) FROM sql_data WHERE sql_data.`销售区域`= '北大区'") d = cur.fetchall() #b = a.__str__() cur.close() conn.close return a,b,c,d ##返回b的值 t = tuple(newcreated()) #print(t) class control : def __init__(self, master): ##用来建造GUI 控制界面 fm1 = Frame(master) Button(fm1, text='生成数据',command = self.exc).pack(side=TOP, anchor=W, fill=X, expand=NO,padx = 10, pady = 10,ipadx=10,ipady = 4) fm1.pack(side=LEFT, fill=BOTH, expand=YES) def exc(self): ##用来提取表格,并对表格进行赋值的 wb = openpyxl.load_workbook('C:/Users/lenovo/Desktop/小小科技/show_6.15/6_15/show_6_15.xlsx') sheet = wb.get_sheet_by_name('页签1') sheet['C4'] = t [0][0][0] sheet['C5'] = t [1][0][0] sheet['C6'] = t [2][0][0] sheet['C7'] = t [3][0][0] print(sheet['C4'].value) print(sheet['C5'].value) print(sheet['C6'].value) print(sheet['C7'].value) wb.save('show_6_15.xlsx') root = Tk() root.title("Control") display = control(root) root.mainloop() ```

python问题:TypeError: expected string or buffer

``` import requests import re #这是用requests进行的数据爬取 url = 'https://car.autohome.com.cn/photo/series/26709/1/3793691.html' html = requests.get(url) # print (html.text) img_url = re.findall(r'<img id="img" src="(.*?)"',html)[0] img_url = 'http:' + img_url print(img_url) img_response = requests.get(img_url) img_data = img_response.content f = open('2.jpg','wb') f.write(img_data) f.close() 报错: Traceback (most recent call last): File "D:/Java/Python/src/hao/__init__.py", line 9, in <module> img_url = re.findall(r'<img id="img" src="(.*?)"',html)[0] File "C:\Python27\lib\re.py", line 181, in findall return _compile(pattern, flags).findall(string) TypeError: expected string or buffer ```

关于python2使用beautifulsoup定位元素的问题

![图片说明](https://img-ask.csdn.net/upload/201708/07/1502091057_104856.png) 详细图片![图片说明](https://img-ask.csdn.net/upload/201708/07/1502091430_831817.png) 小弟刚学习爬虫,公司有个相关的记录需要我爬取一下,请问各位大神我怎么样能够定位到图中蓝色的部分 页面已经爬取放在了soup中,我自己的方法是 res_node=soup.find('span',class_='text') 但是死活不出数据,请问问题是出在哪里?先谢谢各位了

python+opencv+pyqt5 车牌批量识别报错

**我在单个识别的基础上更改了代码,改成了批量识别,运行程序报错:** **Process finished with exit code -1073740791 (0xC0000409)** 以下是识别单个图片的代码,运行OK ``` from PyQt5 import QtCore,QtGui, QtWidgets from PyQt5.QtGui import * from PyQt5.QtCore import Qt from PyQt5.QtWidgets import * from Recognition import PlateRecognition import cv2 import sys, os, xlwt import numpy as np class Ui_MainWindow(object): def __init__(self): self.RowLength = 0 self.Data = [['文件名称', '录入时间', '车牌号码', '车牌类型', '识别耗时', '车牌信息']] def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(1213, 670) MainWindow.setFixedSize(1213, 670) # 设置窗体固定大小 MainWindow.setToolButtonStyle(QtCore.Qt.ToolButtonIconOnly) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.scrollArea = QtWidgets.QScrollArea(self.centralwidget) self.scrollArea.setGeometry(QtCore.QRect(690, 10, 511, 491)) self.scrollArea.setWidgetResizable(True) self.scrollArea.setObjectName("scrollArea") self.scrollAreaWidgetContents = QtWidgets.QWidget() self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 509, 489)) self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents") self.label_0 = QtWidgets.QLabel(self.scrollAreaWidgetContents) self.label_0.setGeometry(QtCore.QRect(10, 10, 111, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_0.setFont(font) self.label_0.setObjectName("label_0") self.label = QtWidgets.QLabel(self.scrollAreaWidgetContents) self.label.setGeometry(QtCore.QRect(10, 40, 481, 441)) self.label.setObjectName("label") self.label.setAlignment(Qt.AlignCenter) self.scrollArea.setWidget(self.scrollAreaWidgetContents) self.scrollArea_2 = QtWidgets.QScrollArea(self.centralwidget) self.scrollArea_2.setGeometry(QtCore.QRect(10, 10, 671, 631)) self.scrollArea_2.setWidgetResizable(True) self.scrollArea_2.setObjectName("scrollArea_2") self.scrollAreaWidgetContents_1 = QtWidgets.QWidget() self.scrollAreaWidgetContents_1.setGeometry(QtCore.QRect(0, 0, 669, 629)) self.scrollAreaWidgetContents_1.setObjectName("scrollAreaWidgetContents_1") self.label_1 = QtWidgets.QLabel(self.scrollAreaWidgetContents_1) self.label_1.setGeometry(QtCore.QRect(10, 10, 111, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_1.setFont(font) self.label_1.setObjectName("label_1") self.tableWidget = QtWidgets.QTableWidget(self.scrollAreaWidgetContents_1) self.tableWidget.setGeometry(QtCore.QRect(10, 40, 651, 581)) # 581)) self.tableWidget.setObjectName("tableWidget") self.tableWidget.setColumnCount(6) self.tableWidget.setColumnWidth(0, 140) # 设置1列的宽度 self.tableWidget.setColumnWidth(1, 130) # 设置2列的宽度 self.tableWidget.setColumnWidth(2, 65) # 设置3列的宽度 self.tableWidget.setColumnWidth(3, 75) # 设置4列的宽度 self.tableWidget.setColumnWidth(4, 65) # 设置5列的宽度 self.tableWidget.setColumnWidth(5, 174) # 设置6列的宽度 self.tableWidget.setHorizontalHeaderLabels(["图片名称", "录入时间", "识别耗时", "车牌号码", "车牌类型", "车牌信息"]) self.tableWidget.setRowCount(self.RowLength) self.tableWidget.verticalHeader().setVisible(False) # 隐藏垂直表头) # self.tableWidget.setStyleSheet("selection-background-color:blue") # self.tableWidget.setAlternatingRowColors(True) self.tableWidget.setEditTriggers(QAbstractItemView.NoEditTriggers) self.tableWidget.raise_() self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_1) self.scrollArea_3 = QtWidgets.QScrollArea(self.centralwidget) self.scrollArea_3.setGeometry(QtCore.QRect(690, 510, 341, 131)) self.scrollArea_3.setWidgetResizable(True) self.scrollArea_3.setObjectName("scrollArea_3") self.scrollAreaWidgetContents_3 = QtWidgets.QWidget() self.scrollAreaWidgetContents_3.setGeometry(QtCore.QRect(0, 0, 339, 129)) self.scrollAreaWidgetContents_3.setObjectName("scrollAreaWidgetContents_3") self.label_2 = QtWidgets.QLabel(self.scrollAreaWidgetContents_3) self.label_2.setGeometry(QtCore.QRect(10, 10, 111, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_2.setFont(font) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(self.scrollAreaWidgetContents_3) self.label_3.setGeometry(QtCore.QRect(10, 40, 321, 81)) self.label_3.setObjectName("label_3") self.scrollArea_3.setWidget(self.scrollAreaWidgetContents_3) self.scrollArea_4 = QtWidgets.QScrollArea(self.centralwidget) self.scrollArea_4.setGeometry(QtCore.QRect(1040, 510, 161, 131)) self.scrollArea_4.setWidgetResizable(True) self.scrollArea_4.setObjectName("scrollArea_4") self.scrollAreaWidgetContents_4 = QtWidgets.QWidget() self.scrollAreaWidgetContents_4.setGeometry(QtCore.QRect(0, 0, 159, 129)) self.scrollAreaWidgetContents_4.setObjectName("scrollAreaWidgetContents_4") self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents_4) self.pushButton_2.setGeometry(QtCore.QRect(20, 50, 121, 31)) self.pushButton_2.setObjectName("pushButton_2") self.pushButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents_4) self.pushButton.setGeometry(QtCore.QRect(20, 90, 121, 31)) self.pushButton.setObjectName("pushButton") self.label_4 = QtWidgets.QLabel(self.scrollAreaWidgetContents_4) self.label_4.setGeometry(QtCore.QRect(10, 10, 111, 20)) font = QtGui.QFont() font.setPointSize(11) self.label_4.setFont(font) self.label_4.setObjectName("label_4") self.scrollArea_4.setWidget(self.scrollAreaWidgetContents_4) MainWindow.setCentralWidget(self.centralwidget) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.pushButton.clicked.connect(self.__openimage) # 设置点击事件 self.pushButton_2.clicked.connect(self.__writeFiles) # 设置点击事件 self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.ProjectPath = os.getcwd() # 获取当前工程文件位置 def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "车牌识别系统")) self.label_0.setText(_translate("MainWindow", "原始图片:")) self.label.setText(_translate("MainWindow", "")) self.label_1.setText(_translate("MainWindow", "识别结果:")) self.label_2.setText(_translate("MainWindow", "车牌区域:")) self.label_3.setText(_translate("MainWindow", "")) self.pushButton.setText(_translate("MainWindow", "打开文件")) self.pushButton_2.setText(_translate("MainWindow", "导出数据")) self.label_4.setText(_translate("MainWindow", "命令:")) self.scrollAreaWidgetContents_1.show() # 识别 def __vlpr(self, path): PR = PlateRecognition() result = PR.VLPR(path) return result def __show(self, result, FileName): # 显示表格 self.RowLength = self.RowLength + 1 if self.RowLength > 18: self.tableWidget.setColumnWidth(5, 157) self.tableWidget.setRowCount(self.RowLength) self.tableWidget.setItem(self.RowLength - 1, 0, QTableWidgetItem(FileName)) self.tableWidget.setItem(self.RowLength - 1, 1, QTableWidgetItem(result['InputTime'])) self.tableWidget.setItem(self.RowLength - 1, 2, QTableWidgetItem(str(result['UseTime']) + '秒')) self.tableWidget.setItem(self.RowLength - 1, 3, QTableWidgetItem(result['Number'])) self.tableWidget.setItem(self.RowLength - 1, 4, QTableWidgetItem(result['Type'])) if result['Type'] == '蓝色牌照': self.tableWidget.item(self.RowLength - 1, 4).setBackground(QBrush(QColor(3, 128, 255))) elif result['Type'] == '绿色牌照': self.tableWidget.item(self.RowLength - 1, 4).setBackground(QBrush(QColor(98, 198, 148))) elif result['Type'] == '黄色牌照': self.tableWidget.item(self.RowLength - 1, 4).setBackground(QBrush(QColor(242, 202, 9))) self.tableWidget.setItem(self.RowLength - 1, 5, QTableWidgetItem(result['From'])) # 显示识别到的车牌位置 size = (int(self.label_3.width()), int(self.label_3.height())) shrink = cv2.resize(result['Picture'], size, interpolation=cv2.INTER_AREA) shrink = cv2.cvtColor(shrink, cv2.COLOR_BGR2RGB) self.QtImg = QtGui.QImage(shrink[:], shrink.shape[1], shrink.shape[0], shrink.shape[1] * 3, QtGui.QImage.Format_RGB888) self.label_3.setPixmap(QtGui.QPixmap.fromImage(self.QtImg)) def __writexls(self, DATA, path): wb = xlwt.Workbook(); ws = wb.add_sheet('Data'); # DATA.insert(0, ['文件名称','录入时间', '车牌号码', '车牌类型', '识别耗时', '车牌信息']) for i, Data in enumerate(DATA): for j, data in enumerate(Data): ws.write(i, j, data) wb.save(path) QMessageBox.information(None, "成功", "数据已保存!", QMessageBox.Yes) def __writecsv(self, DATA, path): f = open(path, 'w') # DATA.insert(0, ['文件名称','录入时间', '车牌号码', '车牌类型', '识别耗时', '车牌信息']) for data in DATA: f.write((',').join(data) + '\n') f.close() QMessageBox.information(None, "成功", "数据已保存!", QMessageBox.Yes) def __writeFiles(self): path, filetype = QFileDialog.getSaveFileName(None, "另存为", self.ProjectPath, "Excel 工作簿(*.xls);;CSV (逗号分隔)(*.csv)") if path == "": # 未选择 return if filetype == 'Excel 工作簿(*.xls)': self.__writexls(self.Data, path) elif filetype == 'CSV (逗号分隔)(*.csv)': self.__writecsv(self.Data, path) def __openimage(self): path, filetype = QFileDialog.getOpenFileName(None, "选择文件", self.ProjectPath, "JPEG Image (*.jpg);;PNG Image (*.png);;JFIF Image (*.jfif)") # ;;All Files (*) if path == "": # 未选择文件 return filename = path.split('/')[-1] # 尺寸适配 size = cv2.imdecode(np.fromfile(path, dtype=np.uint8), cv2.IMREAD_COLOR).shape if size[0] / size[1] > 1.0907: w = size[1] * self.label.height() / size[0] h = self.label.height() jpg = QtGui.QPixmap(path).scaled(w, h) elif size[0] / size[1] < 1.0907: w = self.label.width() h = size[0] * self.label.width() / size[1] jpg = QtGui.QPixmap(path).scaled(w, h) else: jpg = QtGui.QPixmap(path).scaled(self.label.width(), self.label.height()) self.label.setPixmap(jpg) result = self.__vlpr(path) if result is not None: self.Data.append( [filename, result['InputTime'], result['Number'], result['Type'], str(result['UseTime']) + '秒', result['From']]) self.__show(result, filename) else: QMessageBox.warning(None, "Error", "无法识别此图像!", QMessageBox.Yes) # 重写MainWindow类 class MainWindow(QtWidgets.QMainWindow): def closeEvent(self, event): reply = QtWidgets.QMessageBox.question(self, '提示', "是否要退出程序?\n提示:退出后将丢失所有识别数据", QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No, QtWidgets.QMessageBox.No) if reply == QtWidgets.QMessageBox.Yes: event.accept() else: event.ignore() if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = MainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) MainWindow.show() sys.exit(app.exec_()) ``` **我改了一下,如下图,红色标记的添加的批量识别的代码,其他不变** ![图片说明](https://img-ask.csdn.net/upload/202003/19/1584628510_866364.png) ![图片说明](https://img-ask.csdn.net/upload/202003/19/1584629107_129702.png) 求大佬们帮忙看一下添加批量识别的代码是否正确,还有这个错肿么改,小白感激不尽

在中国程序员是青春饭吗?

今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...

程序员请照顾好自己,周末病魔差点一套带走我。

程序员在一个周末的时间,得了重病,差点当场去世,还好及时挽救回来了。

C++(数据结构与算法)78:---分而治之

一、分而治之的思想 分而治之方法与软件设计的模块化方法非常相似 分而治之通常不用于解决问题的小实例,而要解决一个问题的大实例。一般步骤为: ①把一个大实例分为两个或多个更小的实例 ②分别解决每个小实例 ③把这些小实例的解组合成原始大实例的解 二、实际应用之找出假币 问题描述 一个袋子有16个硬币,其中只有一个是假币,这个假币比其他的真币重量轻(其他所有真币的重量都是相同的)...

springboot+jwt实现token登陆权限认证

一 前言 此篇文章的内容也是学习不久,终于到周末有时间码一篇文章分享知识追寻者的粉丝们,学完本篇文章,读者将对token类的登陆认证流程有个全面的了解,可以动态搭建自己的登陆认证过程;对小项目而已是个轻量级的认证机制,符合开发需求;更多精彩原创内容关注公主号知识追寻者,读者的肯定,就是对作者的创作的最大支持; 二 jwt实现登陆认证流程 用户使用账号和面发出post请求 服务器接受到请求后使用私...

技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...

win10暴力查看wifi密码

刚才邻居打了个电话说:喂小灰,你家wifi的密码是多少,我怎么连不上了。 我。。。 我也忘了哎,就找到了一个好办法,分享给大家: 第一种情况:已经连接上的wifi,怎么知道密码? 打开:控制面板\网络和 Internet\网络连接 然后右击wifi连接的无线网卡,选择状态 然后像下图一样: 第二种情况:前提是我不知道啊,但是我以前知道密码。 此时可以利用dos命令了 1、利用netsh wlan...

女程序员,为什么比男程序员少???

昨天看到一档综艺节目,讨论了两个话题:(1)中国学生的数学成绩,平均下来看,会比国外好?为什么?(2)男生的数学成绩,平均下来看,会比女生好?为什么?同时,我又联想到了一个技术圈经常讨...

副业收入是我做程序媛的3倍,工作外的B面人生是怎样的?

提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...

MySQL数据库面试题(2020最新版)

文章目录数据库基础知识为什么要使用数据库什么是SQL?什么是MySQL?数据库三大范式是什么mysql有关权限的表都有哪几个MySQL的binlog有有几种录入格式?分别有什么区别?数据类型mysql有哪些数据类型引擎MySQL存储引擎MyISAM与InnoDB区别MyISAM索引与InnoDB索引的区别?InnoDB引擎的4大特性存储引擎选择索引什么是索引?索引有哪些优缺点?索引使用场景(重点)...

如果你是老板,你会不会踢了这样的员工?

有个好朋友ZS,是技术总监,昨天问我:“有一个老下属,跟了我很多年,做事勤勤恳恳,主动性也很好。但随着公司的发展,他的进步速度,跟不上团队的步伐了,有点...

我入职阿里后,才知道原来简历这么写

私下里,有不少读者问我:“二哥,如何才能写出一份专业的技术简历呢?我总感觉自己写的简历太烂了,所以投了无数份,都石沉大海了。”说实话,我自己好多年没有写过简历了,但我认识的一个同行,他在阿里,给我说了一些他当年写简历的方法论,我感觉太牛逼了,实在是忍不住,就分享了出来,希望能够帮助到你。 01、简历的本质 作为简历的撰写者,你必须要搞清楚一点,简历的本质是什么,它就是为了来销售你的价值主张的。往深...

程序员写出这样的代码,能不挨骂吗?

当你换槽填坑时,面对一个新的环境。能够快速熟练,上手实现业务需求是关键。但是,哪些因素会影响你快速上手呢?是原有代码写的不够好?还是注释写的不够好?昨夜...

带了6个月的徒弟当了面试官,而身为高级工程师的我天天修Bug......

即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

优雅的替换if-else语句

场景 日常开发,if-else语句写的不少吧??当逻辑分支非常多的时候,if-else套了一层又一层,虽然业务功能倒是实现了,但是看起来是真的很不优雅,尤其是对于我这种有强迫症的程序"猿",看到这么多if-else,脑袋瓜子就嗡嗡的,总想着解锁新姿势:干掉过多的if-else!!!本文将介绍三板斧手段: 优先判断条件,条件不满足的,逻辑及时中断返回; 采用策略模式+工厂模式; 结合注解,锦...

!大部分程序员只会写3年代码

如果世界上都是这种不思进取的软件公司,那别说大部分程序员只会写 3 年代码,恐怕就没有程序员这种职业。

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...

2020阿里全球数学大赛:3万名高手、4道题、2天2夜未交卷

阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...

为什么你不想学习?只想玩?人是如何一步一步废掉的

不知道是不是只有我这样子,还是你们也有过类似的经历。 上学的时候总有很多光辉历史,学年名列前茅,或者单科目大佬,但是虽然慢慢地长大了,你开始懈怠了,开始废掉了。。。 什么?你说不知道具体的情况是怎么样的? 我来告诉你: 你常常潜意识里或者心理觉得,自己真正的生活或者奋斗还没有开始。总是幻想着自己还拥有大把时间,还有无限的可能,自己还能逆风翻盘,只不是自己还没开始罢了,自己以后肯定会变得特别厉害...

男生更看重女生的身材脸蛋,还是思想?

往往,我们看不进去大段大段的逻辑。深刻的哲理,往往短而精悍,一阵见血。问:产品经理挺漂亮的,有点心动,但不知道合不合得来。男生更看重女生的身材脸蛋,还是...

为什么程序员做外包会被瞧不起?

二哥,有个事想询问下您的意见,您觉得应届生值得去外包吗?公司虽然挺大的,中xx,但待遇感觉挺低,马上要报到,挺纠结的。

当HR压你价,说你只值7K,你该怎么回答?

当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...

面试:第十六章:Java中级开发

HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...

早上躺尸,晚上干活:硅谷科技公司这么流行迟到?

硅谷科技公司上班时间OPEN早已不是什么新鲜事,早九晚五是常态,但有很多企业由于不打卡,员工们10点、11点才“姗姗来迟”的情况也屡见不鲜。 这种灵活的考勤制度为人羡慕,甚至近年来,国内某些互联网企业也纷纷效仿。不过,硅谷普遍弹性的上班制度是怎么由来的呢?这种“流行性迟到”真的有那么轻松、悠哉吗? 《动态规划专题班》 课程试听内容: 动态规划的解题要领 动态规划三大类 求最值/计数/可行性 常...

面试阿里p7,被按在地上摩擦,鬼知道我经历了什么?

面试阿里p7被问到的问题(当时我只知道第一个):@Conditional是做什么的?@Conditional多个条件是什么逻辑关系?条件判断在什么时候执...

Python爬虫,高清美图我全都要(彼岸桌面壁纸)

爬取彼岸桌面网站较为简单,用到了requests、lxml、Beautiful Soup4

无代码时代来临,程序员如何保住饭碗?

编程语言层出不穷,从最初的机器语言到如今2500种以上的高级语言,程序员们大呼“学到头秃”。程序员一边面临编程语言不断推陈出新,一边面临由于许多代码已存在,程序员编写新应用程序时存在重复“搬砖”的现象。 无代码/低代码编程应运而生。无代码/低代码是一种创建应用的方法,它可以让开发者使用最少的编码知识来快速开发应用程序。开发者通过图形界面中,可视化建模来组装和配置应用程序。这样一来,开发者直...

面试了一个 31 岁程序员,让我有所触动,30岁以上的程序员该何去何从?

最近面试了一个31岁8年经验的程序猿,让我有点感慨,大龄程序猿该何去何从。

大三实习生,字节跳动面经分享,已拿Offer

说实话,自己的算法,我一个不会,太难了吧

程序员垃圾简历长什么样?

已经连续五年参加大厂校招、社招的技术面试工作,简历看的不下于万份 这篇文章会用实例告诉你,什么是差的程序员简历! 疫情快要结束了,各个公司也都开始春招了,作为即将红遍大江南北的新晋UP主,那当然要为小伙伴们做点事(手动狗头)。 就在公众号里公开征简历,义务帮大家看,并一一点评。《启舰:春招在即,义务帮大家看看简历吧》 一石激起千层浪,三天收到两百多封简历。 花光了两个星期的所有空闲时...

Java岗开发3年,公司临时抽查算法,离职后这几题我记一辈子

前几天我们公司做了一件蠢事,非常非常愚蠢的事情。我原以为从学校出来之后,除了找工作有测试外,不会有任何与考试有关的事儿。 但是,天有不测风云,公司技术总监、人事总监两位大佬突然降临到我们事业线,叫上我老大,给我们组织了一场别开生面的“考试”。 那是一个风和日丽的下午,我翘着二郎腿,左手端着一杯卡布奇诺,右手抓着我的罗技鼠标,滚动着轮轴,穿梭在头条热点之间。 “淡黄的长裙~蓬松的头发...

立即提问
相关内容推荐