我试图抓取出价网站的内容,但无法获取该网站的完整页面.我在xulrunner上使用crowbar首先获取页面(因为ajax以懒惰方式加载某些元素)然后从文件中删除.但是在bidrivals网站的主页上,即使本地文件格式正确,也会失败.jSoup似乎只是在html代码中途以'...'字符结束.如果有人以前遇到过此,请帮忙.为[ 此链接 ] 调用以下代码.
File f = new File(projectLocation+logFile+"bidrivalsHome");
try {
f.createNewFile();
log.warn("Trying to fetch mainpage through a console.");
WinRedirect.redirect(projectLocation+"Curl.exe -s --data \"url="+website+"&delay="+timeDelay+"\" http://127.0.0.1:10000", projectLocation, logFile+"bidrivalsHome");
} catch (Exception e) {
e.printStackTrace();
log.warn("Error in fetching the nameList", e);
}
Document doc = new Document("");
try {
doc = Jsoup.parse(f, "UTF-8", website);
} catch (IOException e1) {
System.out.println("Error while parsing the document.");
e1.printStackTrace();
log.warn("Error in parsing homepage", e1);
}
Run Code Online (Sandbox Code Playgroud) 我有这个需要解析的HTML代码
<a class="sushi-restaurant" href="/greatSushi">Best Sushi in town</a>
我知道有一个jsoup的例子,你可以获得页面中的所有链接,例如
Elements links = doc.select("a[href]");
for (Element link : links) {
print(" * a: <%s> (%s)", link.attr("abs:href"),
trim(link.text(), 35));
}
Run Code Online (Sandbox Code Playgroud)
但我需要一段代码,可以返回给我特定类的href.
多谢你们
我正在尝试使用jsoup来清理从我的客户端中的一个wysiwyg发布的html(当它发生时)
松弛模式看起来不够宽松,因为默认情况下它会剥离span元素和任何样式属性.
例如
String text = "<p style="color: #ff0000;">foobar</p>";
Jsoup.clean(text, Whitelist.relaxed());
Run Code Online (Sandbox Code Playgroud)
会输出
<p>foobar</p>
Run Code Online (Sandbox Code Playgroud)
和
<span>foobar</span>
Run Code Online (Sandbox Code Playgroud)
将完全删除.
有没有人有任何使用Jsoup消除XSS攻击可能性的经验,仍然允许上述元素和属性通过?
编辑:我已经使用以下内容了.任何人都可以建议这是多么脆弱吗?
Jsoup.clean(pitch, Whitelist.relaxed().addTags("span").addAttributes(":all","style"));
Run Code Online (Sandbox Code Playgroud)
编辑2:是否有人在生产中使用了owasp库.它看起来正确消毒,同时保留正确的样式.OWASP
我需要从这样的节点中提取文本:
<div>
Some text <b>with tags</b> might go here.
<p>Also there are paragraphs</p>
More text can go without paragraphs<br/>
</div>
Run Code Online (Sandbox Code Playgroud)
我需要建立:
Some text <b>with tags</b> might go here.
Also there are paragraphs
More text can go without paragraphs
Run Code Online (Sandbox Code Playgroud)
Element.text只返回div的所有内容.Element.ownText - 所有不属于儿童元素的东西.两者都错了.迭代children忽略文本节点.
是否有方法迭代元素的内容以接收文本节点.例如
我正在使用jsoup,整理一些html非常好,但我有一个无效的html如下:
<p>The recurrence, in close succession <ul><li>list item 1</li><li>list item 2</li></ul> second part of thisssss
Run Code Online (Sandbox Code Playgroud)
我想得到的是:
<p>The recurrence, in close succession </p><ul><li>list item 1</li><li>list item 2</li></ul> <p>second part of thisssss</p>
Run Code Online (Sandbox Code Playgroud)
那么jsoup能够整理html并返回这个输出吗?
谢谢
在jsoup中Element.children()返回Element的所有子项(后代).但是,我想要Element的一级孩子(直接孩子).
我可以使用哪种方法?
我想删除html div和table表格标签及其中的任何内容(孩子们),最好的方法是什么?
我尝试遍历这样的文档,但它不起作用,在Jsoup文档中它说node.remove()从DOM和他的孩子中删除元素:
doc.traverse(new NodeVisitor() {
@Override
public void head(Node node, int i) {
}
@Override
public void tail(Node node, int i) {
//Log.i(TAG,"node: "+node.nodeName());
if( node.nodeName().compareTo("table") == 0 ||
node.nodeName().compareTo("div") == 0 )
node.remove();
}
});
Run Code Online (Sandbox Code Playgroud) 我试图从评论页面抓取用户对imdb影院电影的评分:(我数据库中的电影数量约为600,000).我使用jsoup来解析页面如下:(对不起,我没有在这里编写整个代码,因为它太长了)
try {
//connecting to mysql db
ResultSet res = st
.executeQuery("SELECT id, title, production_year " +
"FROM title " +
"WHERE kind_id =1 " +
"LIMIT 0 , 100000");
while (res.next()){
.......
.......
String baseUrl = "http://www.imdb.com/search/title?release_date=" +
""+year+","+year+"&title="+movieName+"" +
"&title_type=feature,short,documentary,unknown";
Document doc = Jsoup.connect(baseUrl)
.userAgent("Mozilla")
.timeout(0).get();
.....
.....
//insert ratings into database
...
Run Code Online (Sandbox Code Playgroud)
我测试了它的前100个,然后是前500个,也是我的数据库中的前2000个电影,它运行良好.但问题是,当我测试了100,000部电影时,我收到了这个错误:
org.jsoup.HttpStatusException: HTTP error fetching URL. Status=500, URL=http://www.imdb.com/search/title?release_date=1899,1899&title='Columbia'%20Close%20to%20the%20Wind&title_type=feature,short,documentary,unknown
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:449)
at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:424)
at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:178)
at org.jsoup.helper.HttpConnection.get(HttpConnection.java:167)
at imdb.main(imdb.java:47)
Run Code Online (Sandbox Code Playgroud)
我搜索了很多这个错误,我发现它是一个服务器端错误,错误号为5xx.
然后我决定设置一个条件,当连接失败时,它再尝试2次然后如果仍然无法连接,则不会停止并转到下一个URL.因为我是java的新手,所以我试图在stackoverflow中搜索类似的问题并阅读这些答案:
但是,当我按照他们的建议尝试使用"Connection.Response"时,它会告诉我"Connection.Response无法解析为某种类型".
我很感激,如果有人可以帮助我,因为我只是一个新手,我知道它可能很简单,但我不知道如何解决它. …
我试图解析以下URL的html:
https://www.smuc.ac.kr/mbs/smuc/jsp/board/list.jsp?boardId=6993&id=smuc_040100000000
我收到以下错误:
sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:387)
at sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:292)
at sun.security.validator.Validator.validate(Validator.java:260)
at sun.security.ssl.X509TrustManagerImpl.validate(X509TrustManagerImpl.java:324)
at sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:229)
at sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:124)
at sun.security.ssl.ClientHandshaker.serverCertificate(ClientHandshaker.java:1491)
... 15 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:141)
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:126)
at java.security.cert.CertPathBuilder.build(CertPathBuilder.java:280)
at sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:382)
... 21 more
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
public class MainActivity extends AppCompatActivity {
private ListView listView;
private TextView textView;
public ArrayList<String> arrayList = new ArrayList<String>();
private ArrayAdapter<String> arrayAdapter; …Run Code Online (Sandbox Code Playgroud) 我曾经问过如何检索视频文件的嵌入式网址并成功完成的问题.现在我有一个不同的问题.WUnderground API网络摄像头响应的json响应提供以下URL:
https://www.wunderground.com/webcams/cadot1/902/show.html
使用JSoup并根据我的初始问题的答案,我能够得到这个嵌入式链接:
https://www.wunderground.com/webcams/cadot1/902/video.html?month=11&year=2016&filename=current.mp4
在尝试将视频从该网址"流式传输"到VideoView时,我不断收到错误"无法播放视频".在查看该链接的源代码后,我注意到需要播放的视频文件未在html中引用,而是在javascript中引用.如何获取需要播放的视频文件的直接链接?使用JSoup还是其他进程?
网址源https://www.wunderground.com/webcams/cadot1/902/video.html?month=11&year=2016&filename=current.mp4显示<script>括号内所需视频文件的以下内容:
网址:"//icons.wunderground.com/webcamcurrent/c/a/cadot1/902/current.mp4?e=1480377508"
我正在使用JSoup从响应URL获取视频的嵌入式URL,如下所示:
private class VideoLink extends AsyncTask<Void, Void, Void> {
String title;
@Override
protected void onPreExecute() {
super.onPreExecute();
mProgressDialog.setTitle("JSOUP Test");
mProgressDialog.setMessage("Loading...");
mProgressDialog.setIndeterminate(false);
mProgressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
try {
// for avoiding javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name
System.setProperty("jsse.enableSNIExtension", "false");
// WARNING: do it only if security isn't important, otherwise you have
// to follow this advices: http://stackoverflow.com/a/7745706/1363265
// Create a trust manager that does not validate certificate …Run Code Online (Sandbox Code Playgroud) jsoup ×10
java ×9
android ×2
class ×1
href ×1
html ×1
http-error ×1
https ×1
iteration ×1
security ×1
ssl ×1
web-crawler ×1
web-scraping ×1
wunderground ×1
wysiwyg ×1
xss ×1