首页 文章 精选 留言 我的

精选列表

搜索[API集成],共10008篇文章
优秀的个人博客,低调大师

selenium的文档API

你用WebDriver要做的第一件事就是指定一个链接,一般我们使用get方法: fromseleniumimportwebdriver fromselenium.webdriver.common.keysimportKeys driver=webdriver.Chrome(r'D:\chrome\Google\Chrome\Application\chromedriver.exe') driver.get("https://www.baidu.com/") 你可以用下列任意方法找到它: element=driver.find_element_by_id("passwd-id") element=driver.find_element_by_name("passwd") element=driver.find_element_by_xpath("//input[@id='passwd-id']") content=driver.find_element_by_css_selector('p.content') 等等 fromseleniumimportwebdriver importtime driver=webdriver.Chrome(r'D:\chrome\Google\Chrome\Application\chromedriver.exe') driver.get("https://www.baidu.com/") inputClass=driver.find_element_by_id('kw') time.sleep(3) inputClass.send_keys("python") inputClass.clear() 这里我们举个例子就是请求百度然后输入python然后再删除掉,inputClass.clear()就是清楚搜索框内容假如前面就有内容的话可以先删除掉再输入,这里的kw就是搜索框id 然后我们需要再给我们搜索 fromseleniumimportwebdriver importtime driver=webdriver.Chrome(r'D:\chrome\Google\Chrome\Application\chromedriver.exe') driver.get("https://www.baidu.com/") inputClass=driver.find_element_by_id('kw') inputClass.send_keys("python") time.sleep(3) button=driver.find_element_by_id("su") button.click() 然后我们就可以通过page_source获取搜索后的源代码然后就是beautifulsoup等等包继续获取了 在窗口(window)和框架(frame)间移动现在的网页应用里没有页面框架或者只用一个窗口就包含了所有内容的已经很少了。WebDriver 支持在指定的窗口间移动,方法为switch_to_window: driver.switch_to_window("windowName") 这个switch_to_window用的是target标签现在所有的driver的调用都会指向这个给定的窗口,但是我们怎么知道窗口的名字是什么呢?可以看一看打开这个窗口的javascript脚本或者link链接: Clickheretoopenanewwindow 行为链ActionChains可以完成简单的交互行为,例如鼠标移动,鼠标点击事件,键盘输入,以及内容菜单交互。这对于模拟那些复杂的类似于鼠标悬停和拖拽行为很有用 不管怎样,这些动作总是一个接一个按他们被调用的顺序执行。 click(on_element=None) 点击一个元素 参数: * on_element:要点击的元素,如果是None,点击鼠标当前的位置 click_and_hold(on_element=None) 鼠标左键点击一个元素并且保持 参数: * on_element:同click()类似 double_click(on_element=None) 双击一个元素 参数: * on_element:同click()类似 drag_and_drop(source, target) 鼠标左键点击source元素,然后移动到target元素释放鼠标按键 参数: source:鼠标点击的元素 target:鼠标松开的元素 drag_and_drop_by_offset(source, xoffset,yoffset) 拖拽目标元素到指定的偏移点释放 参数: source:点击的参数 xoffset:X偏移量 * yoffset:Y偏移量 key_down(value,element=None) 只按下键盘,不释放。我们应该只对那些功能键使用(Contril,Alt,Shift) 参数: value:要发送的键,值在Keys类里有定义 element:发送的目标元素,如果是None,value会发到当前聚焦的元素上 例如,我们要按下 ctrl+c: ActionChains(driver).key_down(Keys.CONTROL).send_keys('c').key_up(Keys.CONTROL).perform()key_up(value,element=None) 释放键。参考key_down的解释 move_by_offset(xoffset,yoffset) 将当前鼠标的位置进行移动 参数: xoffset:要移动的X偏移量,可以是正也可以是负 yoffset:要移动的Y偏移量,可以是正也可以是负 move_to_element(to_element) 把鼠标移到一个元素的中间 参数: * to_element:目标元素 move_to_element_with_offset(to_element,xoffset,yoffset) 鼠标移动到元素的指定位置,偏移量以元素的左上角为基准 参数: to_element:目标元素 xoffset:要移动的X偏移量 * yoffset:要移动的Y偏移量 perform() 执行所有存储的动作 release(on_element=None) 释放一个元素上的鼠标按键, 参数: * on_element:如果为None,在当前鼠标位置上释放 send_keys(*keys_to_send) 向当前的焦点元素发送键 参数: * keys_to_send:要发送的键,修饰键可以到Keys类里找到 send_keys_to_element(element,*keys_to_send) 向指定的元素发送键

优秀的个人博客,低调大师

文档API

8.2.1.快速上手 文档通过 _index、_type、_id 元数据(metadata),确定 URL 唯一 GET /<_index>/<_type>/<_id> # curl -XPUT 'http://localhost:9200/website/profile/1' -d '{ "name" : "neo", "nickname" : "netkiller", "age" : "35", "message" : "Helloworld !!!" }' # curl -XGET 'http://localhost:9200/website/profile/1?pretty' { "_index" : "website", "_type" : "profile", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "name" : "neo", "nickname" : "netkiller", "age" : "35", "message" : "Helloworld !!!" } } # curl -XPUT 'http://localhost:9200/website/blog/1?pretty' -d '{ > "title": "My first blog entry", > "text": "Just trying this out...", > "date": "2014/01/01" > }' { "_index" : "website", "_type" : "blog", "_id" : "1", "_version" : 1, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "created" : true } 后面会详细讲解 PUT与GET的使用方法以及相关参数 8.2.2.写入 PUT/POST 通过 PUT 写入数据 [root@localhost ~]# curl -XPUT 'http://localhost:9200/twitter/tweet/1' -d '{ > "user" : "kimchy", > "post_date" : "2009-11-15T14:12:12", > "message" : "trying out Elasticsearch" > }' {"_index":"twitter","_type":"tweet","_id":"1","_version":1,"_shards":{"total":2,"successful":1,"failed":0},"created":true} 使用 UUID 替代 _id, 注意使用UUID 必须使用 POST方式提交,不能使用 PUT。 curl -XPOST 'http://localhost:9200/website/news/?pretty' -d '{ "title": "My first news entry", "text": "Just trying this out..." }' { "_index" : "website", "_type" : "news1", "_id" : "AVY0RJrvJRTrBLpmYzBH", "_version" : 1, "_shards" : { "total" : 2, "successful" : 1, "failed" : 0 }, "created" : true } curl -XGET 'http://localhost:9200/website/news/AVY0RJrvJRTrBLpmYzBH?pretty' 提交后会输出 "_id" : "AVY0RJrvJRTrBLpmYzBH",查询时将此放到放到URL中即可。 8.2.3.获取 GET 通过 GET 读取数据 [root@localhost ~]# curl -XGET 'http://localhost:9200/twitter/tweet/1' {"_index":"twitter","_type":"tweet","_id":"1","_version":1,"found":true,"_source":{ "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" }} 8.2.3.1._source 只返回 _source 数据,去掉元数据 # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2/_source?pretty' { "title" : "My first news entry", "text" : "Just trying this out..." } 选择字段 _source=title,超过一个字段使用逗号分隔_source=title,text。 # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2?_source=title&pretty' { "_index" : "website", "_type" : "news1", "_id" : "AVY0Q4SqdtH0Up0t-WB2", "_version" : 1, "found" : true, "_source" : { "title" : "My first news entry" } } # curl -XGET 'http://localhost:9200/website/news1/AVY0Q4SqdtH0Up0t-WB2?_source=title,text&pretty' { "_index" : "website", "_type" : "news1", "_id" : "AVY0Q4SqdtH0Up0t-WB2", "_version" : 1, "found" : true, "_source" : { "text" : "Just trying this out...", "title" : "My first news entry" } } 8.2.4.检查记录是否存在 [root@localhost elasticsearch]# curl -i -XHEAD http://localhost:9200/website/blog/1 HTTP/1.1 200 OK Content-Type: text/plain; charset=UTF-8 Content-Length: 0 [root@localhost elasticsearch]# curl -i -XHEAD http://localhost:9200/website/blog/100 HTTP/1.1 404 Not Found Content-Type: text/plain; charset=UTF-8 Content-Length: 0 HTTP/1.1 200 OK 表示已经找到你要的数据 HTTP/1.1 404 Not Found 表示数据不存在 8.2.5.删除 Delete 删除 _index curl -XDELETE http://localhost:9200/information/?pretty 删除 _mapping curl -XDELETE http://localhost:9200/information/news/_mapping?pretty 删除对象 curl -XDELETE http://localhost:9200/information/news/1?pretty 8.2.6.参数 8.2.6.1.pretty 格式化 json # curl -XGET 'http://localhost:9200/twitter/tweet/1?pretty' { "_index" : "twitter", "_type" : "tweet", "_id" : "1", "_version" : 1, "found" : true, "_source" : { "user" : "kimchy", "post_date" : "2009-11-15T14:12:12", "message" : "trying out Elasticsearch" } } 原文出处:Netkiller 系列 手札 本文作者:陈景峯 转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

优秀的个人博客,低调大师

Elasticsearch常用操作API

1. 查询所有的索引 1 2 3 4 [root@Server01cx] #curl'10.0.0.5:9200/_cat/indices?v' healthstatusindexprirepdocs.countdocs.deletedstore.sizepri.store.size yellow open customer51206.6kb6.6kb yellow open bank5110000442.1kb442.1kb 2. 查询bank表中的所有数据 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 [root@Server01cx] #curl'10.0.0.5:9200/bank/_search?q=*&pretty' { "took" :41, "timed_out" : false , "_shards" :{ "total" :5, "successful" :5, "failed" :0 }, "hits" :{ "total" :1000, "max_score" :1.0, "hits" :[{ "_index" : "bank" , "_type" : "account" , "_id" : "25" , "_score" :1.0, "_source" :{ "account_number" :25, "balance" :40540, "firstname" : "Virginia" , "lastname" : "Ayala" , "age" :39, "gender" : "F" , "address" : "171PutnamAvenue" , "employer" : "Filodyne" , "email" : "virginiaayala@filodyne.com" , "city" : "Nicholson" , "state" : "PA" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "44" , "_score" :1.0, "_source" :{ "account_number" :44, "balance" :34487, "firstname" : "Aurelia" , "lastname" : "Harding" , "age" :37, "gender" : "M" , "address" : "502BaycliffTerrace" , "employer" : "Orbalix" , "email" : "aureliaharding@orbalix.com" , "city" : "Yardville" , "state" : "DE" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "99" , "_score" :1.0, "_source" :{ "account_number" :99, "balance" :47159, "firstname" : "Ratliff" , "lastname" : "Heath" , "age" :39, "gender" : "F" , "address" : "806RockwellPlace" , "employer" : "Zappix" , "email" : "ratliffheath@zappix.com" , "city" : "Shaft" , "state" : "ND" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "119" , "_score" :1.0, "_source" :{ "account_number" :119, "balance" :49222, "firstname" : "Laverne" , "lastname" : "Johnson" , "age" :28, "gender" : "F" , "address" : "302HowardPlace" , "employer" : "Senmei" , "email" : "lavernejohnson@senmei.com" , "city" : "Herlong" , "state" : "DC" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "126" , "_score" :1.0, "_source" :{ "account_number" :126, "balance" :3607, "firstname" : "Effie" , "lastname" : "Gates" , "age" :39, "gender" : "F" , "address" : "620NationalDrive" , "employer" : "Digitalus" , "email" : "effiegates@digitalus.com" , "city" : "Blodgett" , "state" : "MD" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "145" , "_score" :1.0, "_source" :{ "account_number" :145, "balance" :47406, "firstname" : "Rowena" , "lastname" : "Wilkinson" , "age" :32, "gender" : "M" , "address" : "891EltonStreet" , "employer" : "Asimiline" , "email" : "rowenawilkinson@asimiline.com" , "city" : "Ripley" , "state" : "NH" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "183" , "_score" :1.0, "_source" :{ "account_number" :183, "balance" :14223, "firstname" : "Hudson" , "lastname" : "English" , "age" :26, "gender" : "F" , "address" : "823HerkimerPlace" , "employer" : "Xinware" , "email" : "hudsonenglish@xinware.com" , "city" : "Robbins" , "state" : "ND" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "190" , "_score" :1.0, "_source" :{ "account_number" :190, "balance" :3150, "firstname" : "Blake" , "lastname" : "Davidson" , "age" :30, "gender" : "F" , "address" : "636DiamondStreet" , "employer" : "Quantasis" , "email" : "blakedavidson@quantasis.com" , "city" : "Crumpler" , "state" : "KY" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "208" , "_score" :1.0, "_source" :{ "account_number" :208, "balance" :40760, "firstname" : "Garcia" , "lastname" : "Hess" , "age" :26, "gender" : "F" , "address" : "810NostrandAvenue" , "employer" : "Quiltigen" , "email" : "garciahess@quiltigen.com" , "city" : "Brooktrails" , "state" : "GA" } },{ "_index" : "bank" , "_type" : "account" , "_id" : "222" , "_score" :1.0, "_source" :{ "account_number" :222, "balance" :14764, "firstname" : "Rachelle" , "lastname" : "Rice" , "age" :36, "gender" : "M" , "address" : "333NarrowsAvenue" , "employer" : "Enaut" , "email" : "rachellerice@enaut.com" , "city" : "Wright" , "state" : "AZ" } }] } } took– Elasticsearch执行查询的毫秒响应时间 timed_out– 是否超时 _shards– 查询过的分片,包含成功的分片和失败的分片 hits– 搜索结果 hits.total– 符合搜索结果的记录数 hits.hits– 默认显示前10条搜索结果 _scoreandmax_score- ignore these fields for now 3. 另外一种查询全部结果的方法 1 2 3 4 curl-XPOST '10.0.0.5:9200/bank/_search?pretty' -d' { "query" :{ "match_all" :{}} }' 4. 分页排序的检索例子 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 [root@Server01cx] #curl-XPOST'10.0.0.5:9200/bank/_search?pretty'-d' { "query" :{ "match_all" :{}}, "from" :10, "size" :3, "sort" :{ "balance" :{ "order" : "desc" }} }' { "took" :8, "timed_out" : false , "_shards" :{ "total" :5, "successful" :5, "failed" :0 }, "hits" :{ "total" :1000, "max_score" :null, "hits" :[{ "_index" : "bank" , "_type" : "account" , "_id" : "255" , "_score" :null, "_source" :{ "account_number" :255, "balance" :49339, "firstname" : "Iva" , "lastname" : "Rivers" , "age" :38, "gender" : "M" , "address" : "470RostPlace" , "employer" : "Mantrix" , "email" : "ivarivers@mantrix.com" , "city" : "Disautel" , "state" : "MD" }, "sort" :[49339] },{ "_index" : "bank" , "_type" : "account" , "_id" : "524" , "_score" :null, "_source" :{ "account_number" :524, "balance" :49334, "firstname" : "Salas" , "lastname" : "Farley" , "age" :30, "gender" : "F" , "address" : "499TrucklemansLane" , "employer" : "Xumonk" , "email" : "salasfarley@xumonk.com" , "city" : "Noxen" , "state" : "AL" }, "sort" :[49334] },{ "_index" : "bank" , "_type" : "account" , "_id" : "751" , "_score" :null, "_source" :{ "account_number" :751, "balance" :49252, "firstname" : "Patrick" , "lastname" : "Osborne" , "age" :23, "gender" : "M" , "address" : "915ProspectAvenue" , "employer" : "Gynko" , "email" : "patrickosborne@gynko.com" , "city" : "Takilma" , "state" : "MO" }, "sort" :[49252] }] } } 5. 添加文档,如果id存在则更新文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 [root@Server01data] #curl-XPUT'10.0.0.5:9200/customer/external/1?pretty'-d' >{ "name" : "JohnDoe" }' { "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :1, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "created" : true } [root@Server01data] #curl-XPUT'10.0.0.5:9200/customer/external/1?pretty'-d' { "name" : "JaneDoe" }' { "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :2, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "created" : false } 6. 不指定Id时创建文档,可以发现自动生成一个随机Id 1 2 3 4 5 6 7 8 9 10 11 12 13 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external?pretty'-d'{"name":"JaneDoe"}' { "_index" : "customer" , "_type" : "external" , "_id" : "AVTh53KZ4Pj5B2ZQ2voK" , "_version" :1, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "created" : true } 7. 修改文档 1 2 3 4 5 6 7 8 9 10 11 12 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/2/_update?pretty'-d'{"doc":{"name":"favouriteboy","age":18}}' { "_index" : "customer" , "_type" : "external" , "_id" : "2" , "_version" :3, "_shards" :{ "total" :2, "successful" :1, "failed" :0 } } 8. 在开启javascript后,可以使用JS脚本更新文档 1 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/2/_update?pretty'-d'{"script":"ctx._source.age+=5"}' 9. 删除文档 1 2 3 4 5 6 7 8 9 10 11 12 13 [root@Server01data] #curl-XDELETE'10.0.0.5:9200/customer/external/1?pretty' { "found" : true , "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :4, "_shards" :{ "total" :2, "successful" :1, "failed" :0 } } 10. 批量更新文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/_bulk?pretty'-d' { "index" :{ "_id" : "1" }} { "name" : "JohnDoe" } { "index" :{ "_id" : "2" }} { "name" : "JaneDoe" }' { "took" :33, "errors" : false , "items" :[{ "index" :{ "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :3, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "status" :200 } }] } [root@Server01data] #curl-XPOST'10.0.0.5:9200/customer/external/_bulk?pretty'-d' >{ "update" :{ "_id" : "1" }} >{ "doc" :{ "name" : "JohnDoebecomesJaneDoe" }} >{ "delete" :{ "_id" : "2" }} >' { "took" :34, "errors" : false , "items" :[{ "update" :{ "_index" : "customer" , "_type" : "external" , "_id" : "1" , "_version" :4, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "status" :200 } },{ "delete" :{ "_index" : "customer" , "_type" : "external" , "_id" : "2" , "_version" :5, "_shards" :{ "total" :2, "successful" :1, "failed" :0 }, "status" :200, "found" : true } }] } 本文转自 genuinecx 51CTO博客,原文链接:http://blog.51cto.com/favccxx/1793613,如需转载请自行联系原作者

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册