最近很多小伙伴都在问JSOUP爬虫详细介绍和网上搜不到的一些方法【比较全】和jsoup爬虫教程这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展Array类型II数组用到的一些方法、
最近很多小伙伴都在问JSOUP 爬虫详细介绍和网上搜不到的一些方法【比较全】和jsoup爬虫教程这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展Array类型II 数组用到的一些方法、BeautifulSoup模块详细介绍、Cocos2dx下使用JNI技术调用jar包里面的一些方法遇到的一些问题及解决方案、fastjson 使用方法详细介绍等相关知识,下面开始了哦!
本文目录一览:- JSOUP 爬虫详细介绍和网上搜不到的一些方法【比较全】(jsoup爬虫教程)
- Array类型II 数组用到的一些方法
- BeautifulSoup模块详细介绍
- Cocos2dx下使用JNI技术调用jar包里面的一些方法遇到的一些问题及解决方案
- fastjson 使用方法详细介绍
JSOUP 爬虫详细介绍和网上搜不到的一些方法【比较全】(jsoup爬虫教程)
规则编写说明文档
通用选择器(*)是隐含在没有元素选择器提供 (i.e.
*.header
and.header
is equivalent).样式 匹配 例子 *
任何元素 *
tag
通过Tga标签获取元素 div
ns|E
elements of type E in the namespace ns fb|name
finds<fb:name>
elements#id
elements with attribute ID of "id" div#wrap
,#logo
.class
elements with a class name of "class" div.left
,.result
[attr]
elements with an attribute named "attr" (with any value) a[href]
,[title]
[^attrPrefix]
elements with an attribute name starting with "attrPrefix". Use to find elements with HTML5 datasets [^data-]
,div[^data-]
[attr=val]
elements with an attribute named "attr", and value equal to "val" img[width=500]
,a[rel=nofollow]
[attr="val"]
elements with an attribute named "attr", and value equal to "val" span[hello="Cleveland"][goodbye="Columbus"]
,a[rel="nofollow"]
[attr^=valPrefix]
elements with an attribute named "attr", and value starting with "valPrefix" a[href^=http:]
[attr$=valSuffix]
elements with an attribute named "attr", and value ending with "valSuffix" img[src$=.png]
[attr*=valContaining]
elements with an attribute named "attr", and value containing "valContaining" a[href*=/search/]
[attr~=regex]
elements with an attribute named "attr", and value matching the regular expression img[src~=(?i)\\.(png|jpe?g)]
The above may be combined in any order div.header[title]
组合器
E F
an F element descended from an E element div a
,.logo h1
E > F
an F direct child of E ol > li
E + F
an F element immediately preceded by sibling E li + li
,div.head + div
E ~ F
an F element preceded by sibling E h1 ~ p
E, F, G
all matching elements E, F, or G a[href], div, h3
伪选择器
:lt(n)
elements whose sibling index is less than n td:lt(3)
finds the first 3 cells of each row:gt(n)
elements whose sibling index is greater than n td:gt(1)
finds cells after skipping the first two:eq(n)
elements whose sibling index is equal to n td:eq(0)
finds the first cell of each row:has(selector)
elements that contains at least one element matching the selector div:has(p)
finds divs that contain p elements:not(selector)
elements that do not match the selector. See also Elements.not(String)
div:not(.logo)
finds all divs that do not have the "logo" class.div:not(:has(div))
finds divs that do not contain divs.:contains(text)
elements that contains the specified text. The search is case insensitive. The text may appear in the found element, or any of its descendants. p:contains(jsoup)
finds p elements containing the text "jsoup".:matches(regex)
elements whose text matches the specified regular expression. The text may appear in the found element, or any of its descendants. td:matches(\\d+)
finds table cells containing digits.div:matches((?i)login)
finds divs containing the text, case insensitively.:containsOwn(text)
elements that directly contain the specified text. The search is case insensitive. The text must appear in the found element, not any of its descendants. p:containsOwn(jsoup)
finds p elements with own text "jsoup".:matchesOwn(regex)
elements whose own text matches the specified regular expression. The text must appear in the found element, not any of its descendants. td:matchesOwn(\\d+)
finds table cells directly containing digits.div:matchesOwn((?i)login)
finds divs containing the text, case insensitively.The above may be combined in any order and with other selectors .light:contains(name):eq(0)
结构伪选择器
:root
The element that is the root of the document. In HTML, this is the html
element:root
:nth-child(an+b)
elements that have
In addition to this,an+b-1
siblings before it in the document tree, for any positive integer or zero value ofn
, and has a parent element. For values ofa
andb
greater than zero, this effectively divides the element''s children into groups of a elements (the last group taking the remainder), and selecting the bth element of each group. For example, this allows the selectors to address every other row in a table, and could be used to alternate the color of paragraph text in a cycle of four. Thea
andb
values must be integers (positive, negative, or zero). The index of the first child of an element is 1.:nth-child()
can takeodd
andeven
as arguments instead.odd
has the same signification as2n+1
, andeven
has the same signification as2n
.tr:nth-child(2n+1)
finds every odd row of a table.:nth-child(10n-1)
the 9th, 19th, 29th, etc, element.li:nth-child(5)
the 5h li:nth-last-child(an+b)
elements that have an+b-1
siblings after it in the document tree. Otherwise like:nth-child()
tr:nth-last-child(-n+2)
the last two rows of a table:nth-of-type(an+b)
pseudo-class notation represents an element that has an+b-1
siblings with the same expanded element name before it in the document tree, for any zero or positive integer value of n, and has a parent elementimg:nth-of-type(2n+1)
:nth-last-of-type(an+b)
pseudo-class notation represents an element that has an+b-1
siblings with the same expanded element name after it in the document tree, for any zero or positive integer value of n, and has a parent elementimg:nth-last-of-type(2n+1)
:first-child
elements that are the first child of some other element. div > p:first-child
:last-child
elements that are the last child of some other element. ol > li:last-child
:first-of-type
elements that are the first sibling of its type in the list of children of its parent element dl dt:first-of-type
:last-of-type
elements that are the last sibling of its type in the list of children of its parent element tr > td:last-of-type
:only-child
elements that have a parent element and whose parent element hasve no other element children :only-of-type
an element that has a parent element and whose parent element has no other element children with the same expanded element name :empty
elements that have no children at all MakerAuthor:
Garfield 344892053@qq.com
Array类型II 数组用到的一些方法
concat()方法
这个方法会创建当前数组一个副本,然后将接收到的参数添加到这个副本的末尾,最后返回新数组。没有传递参数的情况系 ,它只是复制当前数组并返回副本。
var color = ["red","green","blue"];
var color2 = color.concat("yellow",["black","gray"]);
alert(color2); //red,green,blue,yellow,black,gray
slice()方法
这个方法可以接受一或两个参数,即要返回项的起始和结束位置。在只有一个参数的情况下,slice()方法返回从该参数指定位置开始到当前数组末尾的所有项。如果有两个参数,返回起始和结束位置之间的项(不包括结束位置的项),slice()方法不会影响原始数组。
var color = ["red","green","blue"];
var color2 = color.slice(1);
var color3 = color.slice(0,2);
alert(color2); //green,blue
alert(color3); //red,green
alert(color); //red,green,blue
splice()方法
有很多种用法,主要用途是向数组的中部插入项。
-删除:指定2个参数,要删除的第一项的位置,要删除的项数。
var color = ["red","green","blue"];
var color2 = color.splice(0,1);
alert(color2); //red
alert(color); //green,blue
-插入:指定3个参数,起始位置,0(要删除的项数),要插入的项。
var color = ["red","green","blue"];
var color2 = color.splice(1,0,"yellow","pink","black"); //在位置1前插入
alert(color2); //没有删除项,所以返回一个空数组
alert(color); //red,yellow,pink,black,green,blue
-替换:指定3个参数,起始位置,要删除的项,要插入的项。
var color = ["red","green","blue"];
var color2 = color.splice(1,2,"yellow","pink","black");
alert(color2); //green,blue
alert(color); //red,yellow,pink,black
indexOf()方法 和 lastIndexOf()方法
这两个方法从接收两个参数:要查找的项,表示查找起点位置的索引(可选)。indexOf()方法从数组的开头向后查找,lastIndexOf()方法则从数组的末尾向前查找。
这两个方法都返回要查找的项在数组中的位置,没找到的情况下返回-1.
var color = ["red","green","blue"];
alert(color.indexOf("green")); //1
alert(color.indexOf("green",2)) //-1 找不到,返回-1
alert(color.lastIndexOf("red")); //0
alert(color.lastIndexOf("green",0)) //-1
迭代方法:ECMAScript5为数组定义了5个迭代方法。每个方法都接收两个参数:要在每一项上运行的函数,运行该函数的作用域对象(可选)
而传入这些方法中的函数会接收三个参数:数组项的值,该项下数组中的位置,数组对象本身
every():检测数组中的每一项是否符合条件,每一项都返回true,则返回true
var num = [1,2,3,4,5];
var result = num.every(function(item,index,array){
return(item > 0);
});
alert(result); //true
some():检测数组中的某一项是否符合条件,只要某一项返回true,则返回true
var num = [1,2,3,4,5];
var result = num.some(function(item,index,array){
return(item > 4);
});
alert(result); //true
filter():筛选出数组中符合条件的项,即返回true的项,返回这些项组成的新数组
var num = [1,2,3,4,5];
var result = num.filter(function(item,index,array){
return(item > 2);
});
alert(result); //3,4,5
map():对数组的每一项运行传入的函数,对应项得出的结果产生一个新数组
var num = [1,2,3,4,5];
var result = num.map(function(item,index,array){
return (item * 2);
});
alert(result); //2,4,6,8,10
forEach():对数组中的每一项运行传入的函数。没有返回值,本质上与使用for循环迭代数组一样
var num = [1,2,3,4,5];
var result = num.forEach(function(item,index,array){
return (item);
});
alert(result); //undefined
两个缩小数组的方法:reduce() 和 reduceRight()方法
这两个方法都会迭代数组的所有项,然后构建一个最终返回的值。reduce()方法从数组的第一项开始,逐个遍历到最后,reduceRight()方法则从数组最后一项开始往前遍历到第一项。
这两个方法都接收两个参数:一个在每一项调用的函数,作为缩小基础的初始值(可选)
调用的函数接收4个参数:前一个值,当前值,项的索引,数组对象
var num = [1,2,3,4,5];
var result = num.reduce(function(prev,cur,index,array){
return (prev*cur);
});
alert(result); //120 =1*2*3*4*5
reduceRight()的作用类似,不过方向相反而已。
BeautifulSoup模块详细介绍
安装lxml,引擎(解析器)
soup=BeautifulSoup(html_doc,features="lxml")
tag=soup.select(‘#link2‘) 选择器的方式
tag.name 获取标签名
children:儿子 标签和内容是不一样的类型
descendants:后代
clear:清空保留标签名 decompose:删除,不保留标签名
extract:删除并有返回值(删除的标签)
encode:把对象转化为字节类型 decode:把对象转化为字符串类型
recursive=True 是否递归去找
soup.find(class_=‘ ‘) class写在attrs外面要加下划线避免与定义类class关键字冲突
. 是通配符除了换行符 \n
tag.get(‘ id ‘) 获取标签属性
www.cnblogs.com/wupeiqi/articles/6283017.html
is_empty_element 是否空标签或自闭合标签
tag.string 不仅可以获取还能修改,标签内容
创建标签:obj=Tag(name=‘div‘,attrs={‘id‘:‘it‘})
jquery.cuishifeng.cn jquery方法大全
tag.wrap(obj) 将obj把tag标签包裹起来
tag.unwrap() 去掉当前标签,保留其包裹的标签
Cocos2dx下使用JNI技术调用jar包里面的一些方法遇到的一些问题及解决方案
情况一:JniHelper.h头文件无法找到
方法:需要添加附加包含目录即可解决问题。具体操作步骤如下:右击项目---->c/c++---->常规---->附加包含目录---->添加JniHelper.h所在的路径即可。此时可能还会遇到找不到jni.h和jni_md.h的问题,解决方案为在%JAVA_HOME%/include/下找到 jni.h,在%JAVA_HOME%/include/win32/下找到jni_md.h,复制到“Visual Studio目录/VC/include/”下,即可解决问题。
情况二:报类似的错。用那个函数,总是报错errorLNK2019:无法解析的外部符号"__declspec(dllimport)public:staticbool__cdeclcocos2d::JniHelper::getStaticmethodInfo(structcocos2d::JniMethodInfo_&,charconst*,charconst*)"(__imp_?getStaticmethodInfo@JniHelper@cocos2d@@SA_NAAUJniMethodInfo_@2@PBD11@Z),该符号在函数"public:staticclasscocos2d::CCScene*__cdeclHelloWorld::scene(void)"(?scene@HelloWorld@@SAPAVCCScene@cocos2d@@XZ)中被引用
方法:#if(CC_TARGET_PLATFORM==CC_PLATFORM_ANDROID)
******************
JNI的代码
***************
#endif
一定要加上平台判断语句。否则会出现以下bug。
情况三:提示在CCPlatformDefine.h文件中log.h: no such file or directory,即log.h找不到。
方法:1.修改Android.mk文件配置,添加如下语句 LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog 2.修改CCPlatformDefine.h文件 注释掉#include "log.h",添加#include "ALog.h"。 3.新建ALog.h文件,写入以下内容,并将其放置于与CCPlatformDefine.h所在的同一目录下。
最后想说的是:编写供c++调用的java方法,如果是第三方jar里面的方法的话,建议用Handler去触发,让其处于在UI线程中运行,否则可能出错。
Cocos新手学习必备源码啊,大量本人写的的源码(有些商业的淘宝店木有放出来,可以私聊),ARPG,动作射击,闯关益智,可学习可运营 个人淘宝店,适合新手,我还可以做技术支持,帮助换皮,带新手等http://shop115423056.taobao.com/?spm=2013.1.1000126.d21.AY74YW
不懂的可以加我的QQ群: 239982941(cocos2d-x 3.x学习群)欢迎你的到来哦,看了博文给点脚印呗,谢谢啦~~
fastjson 使用方法详细介绍
Fastjson介绍
Fastjson是一个Java语言编写的JSON处理器。
1、遵循http://json.org标准,为其官方网站收录的参考实现之一。
2、功能qiang打,支持JDK的各种类型,包括基本的JavaBean、Collection、Map、Date、Enum、泛型。
3、无依赖,不需要例外额外的jar,能够直接跑在JDK上。
4、开源,使用Apache License 2.0协议开源。http://code.alibabatech.com/wiki/display/FastJSON/Home
如果获得Fastjson?
SVN:http://code.alibabatech.com/svn/fastjson/trunk/ WIKI:http://code.alibabatech.com/wiki/display/FastJSON/Home Issue Tracking:http://code.alibabatech.com/jira/browse/FASTJSON
如果你使用了Maven,maven repository配置如下:
<repository> <id>opensesame</id> <name>Alibaba OpenSource Repsoitory</name> <url>http://code.alibabatech.com/mvn/releases/</url> <snapshots> <enabled>false</enabled> </snapshots> </repository>
pom.xml文件中加入依赖依赖:
<dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.0.4</version> </dependency>
如果没有使用maven,可以直接下载:
http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.0.4/fastjson-1.0.4.jar
http://code.alibabatech.com/mvn/releases/com/alibaba/fastjson/1.0.4/fastjson-1.0.4-sources.jar
使用介绍:
Fastjson的最主要的使用入口是com.alibaba.fastjson.JSON
import com.alibaba.fastjson.JSON; public static final Object parse(String text); // 把JSON文本parse为JSONObject或者JSONArray public static final JSONObject parSEObject(String text); // 把JSON文本parse成JSONObject public static final <T> T parSEObject(String text,Class<T> clazz); // 把JSON文本parse为JavaBean public static final JSONArray parseArray(String text); // 把JSON文本parse成JSONArray public static final <T> List<T> parseArray(String text,Class<T> clazz); //把JSON文本parse成JavaBean集合 public static final String toJSONString(Object object); // 将JavaBean序列化为JSON文本 public static final String toJSONString(Object object,boolean prettyFormat); // 将JavaBean序列化为带格式的JSON文本 public static final Object toJSON(Object javaObject); 将JavaBean转换为JSONObject或者JSONArray。
代码示例:
代码示例用到类User和Group:
public class User { private Long id; private String name; public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } public class Group { private Long id; private String name; private List<User> users = new ArrayList<User>(); public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public List<User> getUsers() { return users; } public void setUsers(List<User> users) { this.users = users; } }
Encode代码示例:
import com.alibaba.fastjson.JSON; Group group = new Group(); group.setId(0L); group.setName("admin"); User guestUser = new User(); guestUser.setId(2L); guestUser.setName("guest"); User rootUser = new User(); rootUser.setId(3L); rootUser.setName("root"); group.getUsers().add(guestUser); group.getUsers().add(rootUser); String jsonString = JSON.toJSONString(group); System.out.println(jsonString);
Decode 代码示例:
Group group2 = JSON.parSEObject(jsonString,Group.class);
总结
以上所述是小编给大家介绍的fastjson 使用方法详细介绍,希望对大家有所帮助,如果大家有任何疑问请
给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
关于JSOUP 爬虫详细介绍和网上搜不到的一些方法【比较全】和jsoup爬虫教程的问题我们已经讲解完毕,感谢您的阅读,如果还想了解更多关于Array类型II 数组用到的一些方法、BeautifulSoup模块详细介绍、Cocos2dx下使用JNI技术调用jar包里面的一些方法遇到的一些问题及解决方案、fastjson 使用方法详细介绍等相关内容,可以在本站寻找。
本文标签: