Tag: jsoup

当我使用jsoup或htmlunit获取页面时,href字段丢失

我正在尝试解析谷歌图片搜索结果 。 我正在尝试获取元素的href属性 。 我注意到当我以编程方式获取页面时, href字段丢失了(这与jsoup和htmlunit一起发生)。 比较通过java编程获得的页面元素和实际浏览器加载的页面元素,唯一的区别是,实际上缺少的href字段 (其余部分是相同的)。 href属性(https://stackoverflow.com/questions/39044648/href-field-missing-when-i-get-the-page-using-jsoup-or-htmlunit/IMAGE_LINK)如下: /imgres?imgurl=http%3A%2F%2Fcdn.zonarutoppuden.com%2Fns%2Fpe‌​liculas-naruto-shipp‌​uden.jpg&imgrefurl=h‌​ttp%3A%2F%2Fwww.zona‌​rutoppuden.com%2F201‌​0%2F10%2Fnaruto-ship‌​puden-peliculas.html‌​&docid=JR8NPqKrF3ac_‌​M&tbnid=0EPPOYQcflXk‌​MM%3A&w=900&h=600&bi‌​h=638&biw=1275&ved=0‌​ahUKEwih9O2e88_OAhWM‌​ExoKHRLGAGQQMwg2KAMw‌​Aw&iact=mrc&uact=8 也许javascript引擎存在一些问题? 或者可能是网站使用的某种算法反解析? Snippet Java代码: WebClient webClient = new WebClient(BrowserVersion.CHROME); webClient.waitForBackgroundJavaScript(50000); HtmlPage page1=null; try { // Get the first page page1 = webClient.getPage(URL); System.out.println(page1.asXml()); } catch (FailingHttpStatusCodeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); […]

可以jsoup处理元刷新重定向

我有一个问题,使用jsoup,我想要做的是从url获取一个文件,它将重定向到另一个基于元刷新url的url,这是不起作用,清楚地解释我是否输入了一个名为http://的网站urlwww.amerisourcebergendrug.com将根据元刷新url自动重定向到http://www.amerisourcebergendrug.com/abcdrug/但我的jsoup仍然坚持http://www.amerisourcebergendrug.com而不是重定向和取自http://www.amerisourcebergendrug.com/abcdrug/ Document doc = Jsoup.connect(“http://www.amerisourcebergendrug.com”).get(); 我也试过用, Document doc = Jsoup.connect(“http://www.amerisourcebergendrug.com”).followRedirects(true).get(); 但两者都不起作用 对此有何解决方法? 更新:页面可能使用元刷新重定向方法

如何使用jsoup从HTML解析表

5,390.85 5,428.15 5,376.15 5,413.85 这是HTML源代码,我必须从中提取值5390.85,5428.15,5376.15,5413.85。 我想用jsoup来做这件事。 但我对jsoup相对较新(今天我开始使用它)。 那我该怎么做呢? URL url = new URL(“http://www.nseindia.com/content/equities/niftysparks.htm”); Document doc = Jsoup.parse(url,3*1000); String text = doc.body().text(); 我已经使用jsoup提取了网站的内容。 但如何提取我需要的值? 提前致谢

使用jsoup解析XML – 防止jsoup“清理”标记

在大多数情况下,使用jsoup解析XML没有问题。 但是,如果XML文档中有标记,jsoup会some text here将some text here更改为some text here 。 这使得无法使用CSS选择器在标记内提取文本。 那么如何防止jsoup“清理” 标签?

使用jsoup遍历iframe

我有像这样的html结构。 我想得到没有类或id的第二个表。 我如何从iframe获取第二个表? 我是这样想的 Elements iframe = doc.select(“iframe”); for(Element e : iframe) { System.out.println(e.child(0)); } 谁能帮我?

Jsoup选择并迭代所有元素

我将通过jsoup连接到一个url并获取它的所有内容但是如果我选择喜欢, doc.select(“body”) 它返回一个元素,但我想获取页面中的所有元素并逐个迭代它们,例如, Test Hello All Second Page Test 如果我选择使用body,我会将结果放在一行中,如: Test Hello All Second Page Test 相反,我想选择所有元素并逐个迭代并产生结果,如, Test Hello All Second Page Test 使用jsoup会有可能吗? 谢谢, KARTHIK

如何使用Jsoup将数据发布到网站

我试图将数据发布到网站,使用Jsoup登录网站,但它无法正常工作? 我正在尝试代码 Document docs = Jsoup.connect(“http://some.com/login”) .data(“cmd”, “login”,”username”, “xxxx”,”password”, “yyyyy”) .referrer(“http://some.com/login/”).post(); 这里是在pagesource中提供正常的登录页面 我也尝试过代码 Document docs = (Document) Jsoup.connect(“http://some.com/login”) .data(“cmd”, “login”,”username”, “xxxx”,”password”, “yyyyy”) .referrer(“http://some.com/login/”).method(Method.POST).execute().parse(); 这里也是在pagesource中再次登录的正常页面。 任何有关相同的建议将受到高度赞赏! 谢谢….

如何使用Jsoup从相对HTML链接中提取绝对URL?

我正在使用Jsoup来提取网页的URL。 这些URL的href属性是相对的: example 这是我的尝试: Document document = Jsoup.connect(url).get(); Elements results = document.select(“div.results”); Elements dls = results.select(“dl”); for (Element dl : dls) { String url = dl.select(“a”).attr(“href”); } 这工作正常,但如果我使用 String url = dl.select(“a”).attr(“abs:href”); 要获得像http://example.comhttps://stackoverflow.com/text这样的绝对url,它就无法使用。 我如何获得绝对URL?

如何使用JSoup发布文件?

我使用JSoup使用以下代码发布值: Document document = Jsoup.connect(“http://www……com/….php”) .data(“user”,”user”,”password”,”12345″,”email”,”info@tutorialswindow.com”) .method(Method.POST) .execute() .parse(); 现在我也想提交一份文件。 就像带有文件字段的表单一样。 这可能吗 ? 如果比怎么样?

Jsoup:如何在2个标头标签之间获取所有html

我想在2 h1标签之间获取所有html。 实际任务是将html分解为基于h1(标题1)标记的框架(章节)。 感谢任何帮助。 谢谢Sunil