爬虫中加入请求头导致报错:'str' object has no attribute 'items

在写爬虫时为了规避反爬虫机制,加入了Chrome浏览器请求头.但是在
response = request.Request(url,headers=headers) 语句中加入headers=headers,运行程序时就会报错:'str' object has no attribute 'items.如果只用response = request.Request(url)就不会出现异常而得到正确的爬取结果.求指教,谢谢!!图片说明图片说明

2个回答

headers应该是个dict,例如

#设定请求头中的浏览器标识
headers={"User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36"}

我也遇到了这个问题,拿掉header就可以,否则是爬了几行就报错(我弄了个header的列表,从中随机取header)。
请问楼主有解决办法吗
补充一下,我打印日志检查了的我Header,都是dict类型的。另外,这些header在串行,以及使用进程池的apply_async()时都能正确运行,在使用进程池map方法时就会出这个问题。。。

qq_34298609
qq_34298609 嗯,补充一下,我打印日志检查了的我Header,都是dict类型的。另外,这些header在串行和使用进程池的apply_async方法时都能使用,在使用进程池map方法时就会出这个问题。。。
2 个月之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
小程序使用navigator组件跳转报错

**在wxml中使用navigator传参跳转,代码如下,** **已经在app.json中祖册了post-detail页面,可居然报错页面没找到???** **问题出在哪儿呢?小白求大佬指点指点** ``` <navigator url="/pages/post-detail/post-detail?title={{item.title}}"open-type="navigate"> ``` ``` navigateTo:fail page "pages/post-detail/post-detail?title=%E6%AC%A2%E8%BF%8E%E5%8A%A0%E5%85%A5%E5%BF%83%E7%90%86%E5%8D%8F%E4%BC%9A" is not found ```

如何在Jinja2中渲染时转义双引号?

<div class="post-text" itemprop="text"> <p>我使用Jinja 2和Python 3来创建Golang代码,需要将引号中的一些参数传递给最后代码中的一个函数,但是Jinja 2没有转义双引号。我的python代码类似于:</p> <pre><code>list_s = ['a', 'b'] string = '\"' + '", "'.join(list_s) + '\"' final_string = 'Function(' + string + ')' print(final_string) template.render({'function': final_string}) </code></pre> <p>我的模板是:</p> <pre><code>e.({{function}}) </code></pre> <p>我在控制台中得到的内容(python代码中的print):</p> <pre><code>Function("a", "b") </code></pre> <p>我在最后的代码中想要的是:</p> <pre><code>e.(Function("a", "b")) </code></pre> <p>我在我的最后代码中实际得到的是:</p> <pre><code>e.(Function(&amp;#34;a&amp;#34;, &amp;#34;b&amp;#34;)) </code></pre> <p>我已经试过了:</p> <pre><code>'`\"`' , '`"`', "'\"'", "\\\"", "\N{Quotation Mark}" </code></pre> <p>他们都不像我想的那样工作。有什么想法吗?</p> <p>谢谢 :))</p> <p><strong>"已解决":</strong></p> <p>我的python代码从双引号改为了双引号,所以我的python代码现在是:</p> <pre><code>string = '`' + '`, `'.join(list_s) + '`' </code></pre> <p>我的最终Go代码是:</p> <pre><code>e.(Function(`a`, `b`)) </code></pre> <p>这个就可以了。这不是最好的解决办法,但最起码有用......</p> </div>

CXF实现webservice出错

Caused by: javax.xml.ws.WebServiceException: javax.xml.ws.WebServiceException: Attributes portName, serviceName and endpointInterface are not allowed in the @WebService annotation of an SEI. CXFjar包版本为3.0.9

android studio 报错,请问这是怎么回事?怎么解决

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.b) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.c) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.common.c) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.common.j) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.e) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.j) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.l) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.m) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.d) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.f) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ignoring Error:this warning is that reflective operations on this class will incorrectly Error:indicate that it is *not* an inner class. Error:warning: Ignoring InnerClasses attribute for an anonymous inner class Error:(com.qihoo.sdk.report.g) that doesn't come with an Error:associated EnclosingMethod attribute. This class was probably produced by a Error:compiler that did not target the modern .class file format. The recommended Error:solution is to recompile the class from source, using an up-to-date compiler Error:and without specifying any "-target" type options. The consequence of ig

请问这个该怎么解决啊?debug一个数据库连接的java界面就一直出现这个问题。。。

四月 25, 2020 12:11:25 下午 com.mchange.v2.resourcepool.BasicResourcePool unexpectedBreak 严重: com.mchange.v2.resourcepool.BasicResourcePool@771a4e9b -- Unexpectedly broken!!! com.mchange.v2.resourcepool.ResourcePoolException: Unexpected Break Stack Trace! at com.mchange.v2.resourcepool.BasicResourcePool.unexpectedBreak(BasicResourcePool.java:866) at com.mchange.v2.resourcepool.BasicResourcePool.access$1100(BasicResourcePool.java:32) at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1854) at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

如何从Golang中的XML文件提取多个字段

<div class="post-text" itemprop="text"> <p>Given the following XML file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE tv SYSTEM "xmltv.dtd"&gt; &lt;zoo&gt; &lt;annimal id="1"&gt; &lt;display-name&gt;hyena&lt;/display-name&gt; &lt;/annimal&gt; &lt;annimal id="2"&gt; &lt;display-name&gt;lion&lt;/display-name&gt; &lt;icon src="https://en.wikipedia.org/wiki/File:Lion_waiting_in_Namibia.jpg"/&gt; &lt;/annimal&gt; &lt;annimal id="3"&gt; &lt;display-name&gt;zebra&lt;/display-name&gt; &lt;/annimal&gt; &lt;/zoo&gt; </code></pre> <p>what is the simplest way to produce the following output in golang ?</p> <pre><code>1,hyena 2,lion,https://en.wikipedia.org/wiki/File:Lion_waiting_in_Namibia.jpg 3,zebra </code></pre> </div>

undefined attribute name(v-for)

代码是下面的,用到v-for的地方显示黄色警告,undefined attribute name(v-for) <ul> <li v-for="food in foodList">{{food.name}}: ${{food.price}}</li> </ul> 试过将src换成vue.js的网址也没有用 ``` <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <title>18</title> </head> <body> <div id="app"> <span>hello:{{name}}</span> <ul> <li v-for="food in foodList">{{food.name}}: ${{food.price}}</li> </ul> </div> <script src="${pageContext.request.contextPath}/js/vue.js"></script> <script src="js/main.js"></script> <script> new Vue({ el: '#app', data: { name:hhh foodList:[ { name:meat, price:18, }, { name:fish, price:8, }, ] } }); </script> </body> </html> ``` 直接修改undefined attribute name提示为ignore后就不会出现黄色警告了,但是运行结果还是没有循环,而是直接出现下面两个字符串 hello:{{name}} {{food.name}}: ${{food.price}} 另外就是代码修改后不会马上生效,后加上这段不缓存后又是警告了 求大神指点 ![图片说明](https://img-ask.csdn.net/upload/201907/24/1563929884_352791.png)

Slim + ajax调用“GET”

<div class="post-text" itemprop="text"> <p>im so sorry for my bad english.</p> <p>I have some problems with slim + ajax</p> <p>this is my controller</p> <pre><code>$app-&gt;get('/creazioni(/:lim(/:page))', function($lim = 0, $page = 5) use($app){ </code></pre> <p>and this is my ajax code</p> <pre><code>$.ajax({ //lancio la chiamata principale type : "GET", data : "lim=" + lim + "&amp;page=" + pag, url : 'http://www.urltest.it/creazioni/', success : function(data) { $('#stampa').empty(); $('#stampa').html(data); } </code></pre> <p>console error return a 404 or 509 if i remove / from url:'<a href="http://www.urltest.it/creazioni/" rel="nofollow">http://www.urltest.it/creazioni/</a> it's around 3 days that u try to solve this problem. i making a pagination bu actualy not work xD</p> <p>Thanks for answer and another time sorry for my english</p> </div>

基于数据库记录/召回的动态变量 - 帮助?

<div class="post-text" itemprop="text"> <p>OK, I'll keep this as short as I can..</p> <p>I am trying to create a truly scalable environment for my users and so allow them to..<br> 1. define a new option (dshop_options_name)<br> 2. define option values (dshop_options_values)<br> separate tables in the database</p> <p>This is to allow distinct values to be assigned and also in any combination.<br> OK, the script is in 2 parts. The form page and the result page</p> <p><strong>form.php (using POST)</strong></p> <p>first I need to create dropdowns dynamically based on the options assigned to the product, and then run through the dshop_options_values table to get any values assigned to that option</p> <p>//////////////////////////////////////////////////////////////////////////////////////////</p> <pre><code>$prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`"); $prod_prop_name_array= array(); while($data9=mysql_fetch_array($prod_prop_name)) { $prod_prop_name_array[]=$data9; } foreach($prod_prop_name_array as $rowNum =&gt; $data9) { $prod_prop_id=$data9[0]; $prod_prop_title=$data9[1]; $prod_prop_attri=mysql_query("SELECT * FROM `dshop_options_values` WHERE `prod_id`='".$selected_product."' AND `attri_name`='".$prod_prop_title."' ORDER BY `attri_value` ASC "); $prod_prop_attri_array= array(); while($data10=mysql_fetch_array($prod_prop_attri)) { $prod_prop_attri_array[]=$data10; } if(!$prod_prop_attri_array){} else{ echo"&lt;div class='left'&gt;"; echo"$prod_prop_title ";?&gt; &lt;select name='&lt;? echo $prod_prop_title?&gt;'&gt; &lt;option value="select"&gt;Select&lt;/option&gt; &lt;?php foreach($prod_prop_attri_array as $rowNum =&gt; $data10){ $itemname=$data10[2]; $itemvalue=$data10[3]; $itemprice=$data10[4]; if($itemprice&lt;="0"){ echo"&lt;option value='".$itemvalue."'&gt;".$itemvalue."&lt;/option&gt; "; } else{ echo"&lt;option value='".$itemvalue."'&gt;".$itemvalue."&amp;nbsp;-&amp;nbsp;".$currency_type.$itemprice."&lt;/option&gt; "; } } echo"&lt;/select&gt;&lt;/br&gt;&lt;/br&gt;&lt;/div&gt;"; } </code></pre> <p>}</p> <p>//////////////////////////////////////////////////////////////////////////////////////////</p> <p>ok, as you can see, I name the select the same as the option name, this is so I then use that name to again call the value in the next script.</p> <p><strong>result.php</strong></p> <p>Ok, to reasemble the data set and match up the result to the data posted, I again, do a few calls to get all the data first.</p> <p>//////////////////////////////////////////////////////////////////////////////////////////</p> <pre><code>$prod_prop_name=mysql_query("SELECT * FROM `dshop_options_name`"); $prod_prop_name_array= array(); while($data9=mysql_fetch_array($prod_prop_name)) { $prod_prop_name_array[]=$data9; } foreach($prod_prop_name_array as $rowNum =&gt; $data9){ $option_id=$data9[0]; $option_name=$data9[1]; $varnval=$_REQUEST[$option_name]; echo"$varnval"; // did we get a result? $results = array(); if(!$varnval | $varnval=="select"){} else{ $results[] = $option_name."-".$varnval; $optpricesum_query=mysql_query("SELECT * FROM `dshop_options_values` WHERE `attri_name`='".$option_name."' AND `attri_value`='".$varnval."'"); $optpricesum_result=mysql_fetch_array($optpricesum_query); $optpricesum=$optpricesum_result[4]; } if(!$varnval | $varnval=="select"){} else{ for ($i=0;$i&lt;=0;$i++){$options.=$results[$i]." | ";} } } </code></pre> <p>//////////////////////////////////////////////////////////////////////////////////////////</p> <p>ok, down to the issue...</p> <p>in the form.php, I am posting a value dynamically created, essentially by the admin user.</p> <p>Lets say they created an option "Foo", and the values "foo1", "foo2", "foo3" (in the admin area)</p> <p>form.php builds the selects by cross referencing the two tables, names the select and then populates it (nothing is pre-defined)</p> <p>then the end user arrives at the form on the front end and on posting the form, they selected "foo3"</p> <p>result.php at first has nothing to <code>_REQUEST</code> (remember we had nothing to define) until it rebuilds the possible vaiables that could have been posted. I then used the foreach to run through all the option names stored with the hope of then creating dynamic variables...<br> <code>$varnval = $_REQUEST[$option_name];</code> </p> <p>I then filter the names that have not been posted with..<br> <code>if(!$varnval | $varnval=="select"){}</code></p> <p>now...</p> <p>Locally I get the value "foo3" no problem, but not on the web server. I then noticed that when using local php (Xampp) values dont even need to be defined $var=$_POST['var']; it will still work.... annoying when debugging!! BUT shows to a point anyways, that the script will work.</p> <p>I placed an <code>echo</code> after the <code>$varnval $_REQUEST</code>, but nothing displays.</p> <p>It seems to me that the <code>$_REQUEST</code> is not getting the variable, either because of the parse or because I have just missed something.</p> <p>I have spent days working on this, trying many different ways but all threads lead nowhere.</p> <p>Maybe I am trying the impossible, but I feel there has to be a way to create a set of variables from database records alone (NOT the other way around as most searches seem to produce)</p> <p>This is my first post here, so i apologise if it is in the wrong place!</p> <p>I thank you in advance for any help</p> </div>

要从各种表中获取信息,请获取“数组到字符串转换”错误

<div class="post-text" itemprop="text"> <p>Sorry, If I sound so dumb on this but recently started php and Codeigniter.</p> <p>On my product page I am able to print product's details except users details.</p> <p>I get 'product id' reference from URL and then try to take reference from 'product id' for 'username' associated with it.</p> <p>Here is the controller:</p> <pre><code>public function index() { $id = $this-&gt;uri-&gt;segment(3); //fetching item details on item page by this item id $data['listings'] = $this-&gt;my_listings_model-&gt;all_listings_details($id); //fetching username of user on item page by this item id $username = $this-&gt;my_listings_model-&gt;get_user_name($id); //fetching user details on item page by this username $data['user_info'] = $this-&gt;my_profile_model-&gt;get_all_details($username); $this-&gt;load-&gt;view('item', $data); } </code></pre> <p>And Model:</p> <pre><code>// Fetch Product details with the help of item id. function all_listings_details($id){ $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('vbc_vacation_item_attri'); $this-&gt;db-&gt;where('vbc_item_id', $id); $query = $this-&gt;db-&gt;get(); $query_result = $query-&gt;result(); return $query_result; } // Function to select username with the help of item id. function get_user_name($id){ $this-&gt;db-&gt;select('v_posting_member'); $this-&gt;db-&gt;from('vbc_vacation_item_attri'); $this-&gt;db-&gt;where('vbc_item_id', $id); $query = $this-&gt;db-&gt;get(); $query_result = $query-&gt;result(); return $query_result; } // Collect *All Details* Of A User.. function get_all_details($username){ $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('vbc_registered_members'); $this-&gt;db-&gt;where('v_member_username', $username); $query = $this-&gt;db-&gt;get(); $result = $query-&gt;result(); return $result; } </code></pre> <p>I have spent some good time trying to fix it but no good.</p> <p>Shows error:</p> <blockquote> <p>Message: Array to string conversion</p> </blockquote> </div>

Golang XML封送两个相同的属性

<div class="post-text" itemprop="text"> <p>I'm forced to work with some poorly designed XML, I'm trying to read this XML into a Go structure. Here's some sample data:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;dictionary&gt; &lt;direction from="lojban" to="English"&gt; &lt;valsi word="cipni" type="gismo"&gt; &lt;rafsi&gt;cpi&lt;/rafsi&gt; &lt;definition&gt;x1 is a bird of species x2&lt;/definition&gt; &lt;notes&gt;&lt;/notes&gt; &lt;/valsi&gt; ... &lt;/direction&gt; &lt;direction from="English" to="lojban"&gt; &lt;nlword word="eagle" valsi="atkuila" /&gt; &lt;nlword word="hawk" sense="bird" valsi="aksiptrina" /&gt; ... &lt;/direction&gt; &lt;/dictionary&gt; </code></pre> <p>My issue is I can either read in nodes or because they both contain the attribute "word":</p> <pre><code>main.NLWord field "Word" with tag "word,attr" conflicts with field "Valsi" with tag "word,attr" </code></pre> <p>I'm starting to think unmarshalling may be the wrong approach as I'd ideally structure the data differently. Should I read the XML in using some other method and build up data structures manually?</p> <pre><code>type Valsi struct { Word string `xml:"word,attr"` Type string `xml:"type,attr"` Def string `xml:"definition"` Notes string `xml:"notes"` Class string `xml:"selmaho"` Rafsi []string `xml:"rafsi"` } //Whoever made this XML structure needs to be painfully taught a lesson... type Collection struct { From string `xml:"from"` To string `xml:"to"` Valsi []Valsi `xml:"valsi"` } type Vlaste struct { Direction []Collection `xml:"direction"` } var httpc = &amp;http.Client{} func parseXML(data []byte) Vlaste { vlaste := Vlaste{} err := xml.Unmarshal(data, &amp;vlaste) if err != nil { fmt.Println("Problem Decoding!") log.Fatal(err) } return vlaste } </code></pre> </div>

只是想获取特定设备的句柄进行通信,一堆LNK2019无法解决,已经要疯了。求大神

各种函数链接库错误(无法解析的外部符号) 本人新手对于如何包含动态链接库也不是很了解,请问这种情况应该怎么配置? 代码如下,就是想根据vID pID找到指定的设备。 函数中SetupDi······,Hid_Get...都报无法解析错误 (CSDN新人,1个C币是全部家当了,跪求) #include "stdafx.h" #include "afxwinappex.h" #include "afxdialogex.h" #include "CommTest.h" #include "MainFrm.h" #include "CommTestDoc.h" #include "CommTestView.h" extern "C" { //declare the C libraries used #include "setupAPI.h" #include "hidsdi.h" } ``` BOOL CCommTestWindow::DeviceOpen(HANDLE &handle, WORD wVID, WORD wPID) { BOOL bRet = FALSE; GUID hidGuid; HDEVINFO hardwareDeviceInfo; SP_INTERFACE_DEVICE_DATA deviceInfoData; PSP_INTERFACE_DEVICE_DETAIL_DATA functionClassDeviceData = NULL; ULONG predictedLength = 0; ULONG requiredLength = 0; CloseHandle(handle); handle = INVALID_HANDLE_VALUE; deviceInfoData.cbSize = sizeof(SP_INTERFACE_DEVICE_DATA); HidD_GetHidGuid(&hidGuid); hardwareDeviceInfo = SetupDiGetClassDevs(&hidGuid, NULL, NULL, (DIGCF_PRESENT | DIGCF_DEVICEINTERFACE)); for (int i = 0; i<128; i++) { if (!SetupDiEnumDeviceInterfaces(hardwareDeviceInfo, 0, &hidGuid, i, &deviceInfoData)) continue; SetupDiGetDeviceInterfaceDetail(hardwareDeviceInfo, &deviceInfoData, NULL, 0, &requiredLength, NULL); predictedLength = requiredLength; functionClassDeviceData = (PSP_INTERFACE_DEVICE_DETAIL_DATA)malloc(predictedLength); if (!functionClassDeviceData) continue; functionClassDeviceData->cbSize = sizeof(SP_INTERFACE_DEVICE_DETAIL_DATA); if (!SetupDiGetDeviceInterfaceDetail(hardwareDeviceInfo, &deviceInfoData, functionClassDeviceData, predictedLength, &requiredLength, NULL)) break; handle = CreateFile(functionClassDeviceData->DevicePath, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL); if (handle != INVALID_HANDLE_VALUE) { HIDD_ATTRIBUTES attri; HidD_GetAttributes(handle, &attri); if ((attri.VendorID == wVID) && (attri.ProductID == wPID)) { bRet = TRUE; break; } CloseHandle(handle); handle = INVALID_HANDLE_VALUE; } } SetupDiDestroyDeviceInfoList(hardwareDeviceInfo); return bRet; } ```

在Codeigniter中首次分页后,不会显示搜索结果

<div class="post-text" itemprop="text"> <p>I am new to Codeigniter and seeking some help here.</p> <p>I am making a test app with pagination. It works fine until the first result but when clicked on 'Next' or 'Any Pagination' tells no results were found.</p> <p>I think it calls for url alright but don't know what else is the problem.</p> <p><a href="http://localhost/admin/search/search-results/2" rel="nofollow">http://localhost/admin/search/search-results/2</a></p> <p>My controller:</p> <pre><code>public function pagination(){ $keyword = $this-&gt;input-&gt;post('search[1]'); $main_keyword = $this-&gt;search_model-&gt;get_city_id_by_input($keyword); $config['base_url'] = base_url().'search/search-results/'; $config['total_rows'] = $this-&gt;search_model-&gt;total_number_of_rows($main_keyword); $config['per_page'] = 1; $config['use_page_numbers'] = TRUE; $config['num_links'] = $this-&gt;search_model-&gt;total_number_of_rows($main_keyword); $config['cur_tag_open'] = '&amp;nbsp;'; $config['next_link'] = 'Next'; $config['prev_link'] = 'Previous'; $this-&gt;pagination-&gt;initialize($config); $data['results'] = $this-&gt;search_model-&gt;get_search_results($main_keyword, $config['per_page'], $this-&gt;uri-&gt;segment(3)); $this-&gt;load-&gt;view('view',$data); } </code></pre> <p>Model:</p> <pre><code>function get_city_id_by_input($keyword){ $this-&gt;db-&gt;select('id'); $this-&gt;db-&gt;from('vbc_city'); $this-&gt;db-&gt;where('v_city_name', $keyword); $query = $this-&gt;db-&gt;get(); $query_result = $query-&gt;result_array(); return $query_result(); } public function total_number_of_rows($main_keyword) { $this-&gt;db-&gt;select('vbc_item_id'); $this-&gt;db-&gt;from('vbc_vacation_item_attri'); $this-&gt;db-&gt;where('v_item_city', $main_keyword); $query = $this-&gt;db-&gt;get(); return $query-&gt;num_rows(); } public function get_search_results($main_keyword, $perpage, $offset) { $this-&gt;db-&gt;select('*'); $this-&gt;db-&gt;from('vbc_vacation_item_attri'); $this-&gt;db-&gt;where('v_item_city', $main_keyword); $this-&gt;db-&gt;limit($perpage, $offset); $query = $this-&gt;db-&gt;get(); $result = $query-&gt;result(); return $result; } </code></pre> <p>Please help.</p> </div>

【求助】代码问题,关于RandomAccessFile类的定长写入读取

正在做一个交作业用的本地小型数据库,在删除属性的部分,听老师的建议把原来的内容用新内容覆盖。但在关于定长写入读取的部分有了错误。代码如下 写入部分: ``` for (int i = 0; i < num; i++) {//写入定长属性名 randoms.writeBytes(RandomAccessFiles.format(attris[i], 20, attris[i].length())); } randoms.write("\r\n".getBytes()); for (int i = 0; i < num; i++) {//写入定长类型 randoms.writeBytes(RandomAccessFiles.format(types[i], 10, types[i].length())); } randoms.write("\r\n".getBytes()); for (int i = 0; i < num; i++) {//写入长度 randoms.writeInt(length[i]); } randoms.write("\r\n".getBytes()); for (int i = 0; i < num; i++) {//写入是否主键 randoms.writeBoolean(key[i]); } randoms.write("\r\n".getBytes()); for (int i = 0; i < num; i++) {//写入是否允许空值 randoms.writeBoolean(isnull[i]); } randoms.write("\r\n".getBytes()); randoms.close(); ``` 这是读取和替换的部分,指针位置是没问题的。value里保存删除后的新内容,最后一并写入 ``` int x = 0; byte[] b = new byte[20]; for (int i = 0; i < num; i++) { random.read(b, 0, 20); if (new String(b).trim().equals(attri)) { //查找属性名 x = i; }else { value.append(new String(b)); } } random.readLine();//将换行符读掉 value.append("\r\n"); s = random.readLine();//类型组 System.out.println(s.length()); System.out.println(s); s = s.substring(0 ,x*10) + s.substring((x + 1)*10, s.length()); //数据类型 //System.out.println(s); value.append(s + "\r\n"); s = random.readLine(); System.out.println(s.length()); s = s.substring(0 ,x*4) + s.substring((x + 1)*4, s.length()); //数据长度 //System.out.println(s); value.append(s + "\r\n"); s = random.readLine(); System.out.println(s.length()); s = s.substring(0, x) + s.substring(x + 1, s.length()); //是否key //System.out.println(s); value.append(s + "\r\n"); s = random.readLine(); System.out.println(s.length()); s = s.substring(0, x) + s.substring(x + 1, s.length()); //是否null //System.out.println(s); value.append(s + "\r\n"); ``` 因为属性组、长度组、标志组都是定长的,删除的时候也只要定长搜索到要删除的属性是第几个,然后用substring方法就可以越过被删除的数据。但是后续测试中发现,substring方法偶尔会出现越界、偶尔不会,但删除了非对应属性的类型。尤其在读取长度那里,用readline方法读取后输出长度,(测试时输入了4个属性,writeInt应该写入四个4字节长度),竟然是9?顿时迷茫了,有大神帮帮忙,检查一下代码吗?

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

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

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

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

我以为我学懂了数据结构,直到看了这个导图才发现,我错了

数据结构与算法思维导图

String s = new String(" a ") 到底产生几个对象?

老生常谈的一个梗,到2020了还在争论,你们一天天的,哎哎哎,我不是针对你一个,我是说在座的各位都是人才! 上图红色的这3个箭头,对于通过new产生一个字符串(”宜春”)时,会先去常量池中查找是否已经有了”宜春”对象,如果没有则在常量池中创建一个此字符串对象,然后堆中再创建一个常量池中此”宜春”对象的拷贝对象。 也就是说准确答案是产生了一个或两个对象,如果常量池中原来没有 ”宜春” ,就是两个。...

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

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

Linux面试题(2020最新版)

文章目录Linux 概述什么是LinuxUnix和Linux有什么区别?什么是 Linux 内核?Linux的基本组件是什么?Linux 的体系结构BASH和DOS之间的基本区别是什么?Linux 开机启动过程?Linux系统缺省的运行级别?Linux 使用的进程间通信方式?Linux 有哪些系统日志文件?Linux系统安装多个桌面环境有帮助吗?什么是交换空间?什么是root帐户什么是LILO?什...

将一个接口响应时间从2s优化到 200ms以内的一个案例

一、背景 在开发联调阶段发现一个接口的响应时间特别长,经常超时,囧… 本文讲讲是如何定位到性能瓶颈以及修改的思路,将该接口从 2 s 左右优化到 200ms 以内 。 二、步骤 2.1 定位 定位性能瓶颈有两个思路,一个是通过工具去监控,一个是通过经验去猜想。 2.1.1 工具监控 就工具而言,推荐使用 arthas ,用到的是 trace 命令 具体安装步骤很简单,大家自行研究。 我的使用步骤是...

学历低,无法胜任工作,大佬告诉你应该怎么做

微信上收到一位读者小涛的留言,大致的意思是自己只有高中学历,经过培训后找到了一份工作,但很难胜任,考虑要不要辞职找一份他能力可以胜任的实习工作。下面是他留言的一部分内容: 二哥,我是 2016 年高中毕业的,考上了大学但没去成,主要是因为当时家里经济条件不太允许。 打工了三年后想学一门技术,就去培训了。培训的学校比较垃圾,现在非常后悔没去正规一点的机构培训。 去年 11 月份来北京找到了一份工...

JVM内存结构和Java内存模型别再傻傻分不清了

JVM内存结构和Java内存模型都是面试的热点问题,名字看感觉都差不多,网上有些博客也都把这两个概念混着用,实际上他们之间差别还是挺大的。 通俗点说,JVM内存结构是与JVM的内部存储结构相关,而Java内存模型是与多线程编程相关,本文针对这两个总是被混用的概念展开讲解。 JVM内存结构 JVM构成 说到JVM内存结构,就不会只是说内存结构的5个分区,而是会延展到整个JVM相关的问题,所以先了解下

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...

Google 与微软的浏览器之争

浏览器再现“神仙打架”。整理 | 屠敏头图 | CSDN 下载自东方 IC出品 | CSDN(ID:CSDNnews)从 IE 到 Chrome,再从 Chrome 到 Edge,微软与...

讲一个程序员如何副业月赚三万的真实故事

loonggg读完需要3分钟速读仅需 1 分钟大家好,我是你们的校长。我之前讲过,这年头,只要肯动脑,肯行动,程序员凭借自己的技术,赚钱的方式还是有很多种的。仅仅靠在公司出卖自己的劳动时...

上班一个月,后悔当初着急入职的选择了

最近有个老铁,告诉我说,上班一个月,后悔当初着急入职现在公司了。他之前在美图做手机研发,今年美图那边今年也有一波组织优化调整,他是其中一个,在协商离职后,当时捉急找工作上班,因为有房贷供着,不能没有收入来源。所以匆忙选了一家公司,实际上是一个大型外包公司,主要派遣给其他手机厂商做外包项目。**当时承诺待遇还不错,所以就立马入职去上班了。但是后面入职后,发现薪酬待遇这块并不是HR所说那样,那个HR自...

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

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

搜狗输入法也在挑战国人的智商!

故事总是一个接着一个到来...上周写完《鲁大师已经彻底沦为一款垃圾流氓软件!》这篇文章之后,鲁大师的市场工作人员就找到了我,希望把这篇文章删除掉。经过一番沟通我先把这篇文章从公号中删除了...

85后蒋凡:28岁实现财务自由、34岁成为阿里万亿电商帝国双掌门,他的人生底层逻辑是什么?...

蒋凡是何许人也? 2017年12月27日,在入职4年时间里,蒋凡开挂般坐上了淘宝总裁位置。 为此,时任阿里CEO张勇在任命书中力赞: 蒋凡加入阿里,始终保持创业者的冲劲,有敏锐的...

总结了 150 余个神奇网站,你不来瞅瞅吗?

原博客再更新,可能就没了,之后将持续更新本篇博客。

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

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

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

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

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

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

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

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

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

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

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

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

什么时候跳槽,为什么离职,你想好了么?

都是出来打工的,多为自己着想

程序员为什么千万不要瞎努力?

本文作者用对比非常鲜明的两个开发团队的故事,讲解了敏捷开发之道 —— 如果你的团队缺乏统一标准的环境,那么即使勤劳努力,不仅会极其耗时而且成果甚微,使用...

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

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

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

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

面试:第十六章:Java中级开发(16k)

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

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

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

终于懂了TCP和UDP协议区别

终于懂了TCP和UDP协议区别

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

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

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

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

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

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

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

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

《经典算法案例》01-08:如何使用质数设计扫雷(Minesweeper)游戏

我们都玩过Windows操作系统中的经典游戏扫雷(Minesweeper),如果把质数当作一颗雷,那么,表格中红色的数字哪些是雷(质数)?您能找出多少个呢?文中用列表的方式罗列了10000以内的自然数、质数(素数),6的倍数等,方便大家观察质数的分布规律及特性,以便对算法求解有指导意义。另外,判断质数是初学算法,理解算法重要性的一个非常好的案例。

《Oracle Java SE编程自学与面试指南》最佳学习路线图(2020最新版)

正确选择比瞎努力更重要!

立即提问
相关内容推荐