如何在Android WebView中使用HitTestResult获取链接图像(而不是图像URL)与Longclick的链接URL(How to get link-URL in Android WebView with HitTestResult for a linked image (and not the image-URL) with Longclick)

我试图抓住webview longclicks来显示上下文菜单。 (请参阅下面的代码)长按图片时,我总是会将图片URL额外获取(对于IMAGE_TYPE的未链接图片和SRC_IMAGE_ANCHOR_TYPE的链接图片)。 但是我怎样才能得到链接URL(而不是图像的URL)的图像与超链接?

最好的,塞巴斯蒂安

        mywebview.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View v) {

                final WebView webview = (WebView) v;
                final WebView.HitTestResult result = webview.getHitTestResult();

                if (result.getType() == SRC_ANCHOR_TYPE) {
                    return true;
                }

                if (result.getType() == SRC_IMAGE_ANCHOR_TYPE) {
                    return true;
                }

                if (result.getType() == IMAGE_TYPE) {
                    return true;
                }

                return false;
            }
        });

I try to catch webview longclicks to show a context menu. (see code below) When longclicking an image, I always get the image-URL as extra (for a not linked image with IMAGE_TYPE and for a linked image with SRC_IMAGE_ANCHOR_TYPE). But how can I get the Link-URL (and not the image-URL) for an image with a hyperlink?

Best, Sebastian

        mywebview.setOnLongClickListener(new OnLongClickListener() {
            public boolean onLongClick(View v) {

                final WebView webview = (WebView) v;
                final WebView.HitTestResult result = webview.getHitTestResult();

                if (result.getType() == SRC_ANCHOR_TYPE) {
                    return true;
                }

                if (result.getType() == SRC_IMAGE_ANCHOR_TYPE) {
                    return true;
                }

                if (result.getType() == IMAGE_TYPE) {
                    return true;
                }

                return false;
            }
        });

原文:https://stackoverflow.com/questions/12168039
2024-03-27 20:03

满意答案

只需打印出找到的图像的src

imgs= soup.find_all('img', class_='_2di5p')
for img in imgs:
    img_url=img["src"]
    print img_url

Just print out the src of the found images.

imgs= soup.find_all('img', class_='_2di5p')
for img in imgs:
    img_url=img["src"]
    print img_url

相关问答

更多

使用BS4,Python和Selenium后解析文本(Parse the text after using BS4, Python and Selenium)

您可以使用stripped_strings属性来拔出每个组件并构造一个字典列表,如下所示: from selenium import webdriver from bs4 import BeautifulSoup import csv browser = webdriver.Firefox() browser.get('http://dyn.com/about/events/') html = browser.page_source soup = BeautifulSoup(html) eve...

网站与BS4刮:无法获取表(Web scraping with BS4: unable to get table)

对我来说,在这里使用任何类型的网页抓取似乎都没有必要。 由于无论如何都可以将数据作为文件下载,因此通过解析需要通过报废来表示数据,这是不够的。 相反,您可以下载数据并将其读入熊猫数据框。 您需要安装熊猫,以防万一您安装了Anaconda,您的计算机上可能已经安装了它,否则您可能需要下载Anaconda并安装pandas:conda install pandas 有关安装熊猫的更多信息 有了熊猫,您可以直接从Excel表格中读取数据: import pandas as pd df = pd.read...

用Python / BS4刮表(Scraping Table With Python/BS4)

在这种情况下的问题是“团队统计信息”表位于 HTML源代码中的注释内 ,您可以使用requests下载该注释 。 找到注释并使用BeautifulSoup将其解析为“汤”对象: import requests from bs4 import BeautifulSoup, NavigableString url = 'http://www.pro-football-reference.com/boxscores/201602070den.htm' page = requests.get(url, ...

使用BS4解析HTML表(Parsing HTML Tables with BS4)

我只用了8个小时左右就知道了。 学习很有趣。 谢谢Kevin的帮助! 它现在包含将已删除数据输出到csv文件的代码。 接下来是获取该数据并过滤掉某些位置.... 这是我的代码: import urllib2 from bs4 import BeautifulSoup import csv url = ('http://nflcombineresults.com/nflcombinedata.php?year=2000&pos=&college=') page = urllib2.urlopen...

Img使用bs4和硒进行刮擦(Img scraping using bs4 and selenium)

只需打印出找到的图像的src 。 imgs= soup.find_all('img', class_='_2di5p') for img in imgs: img_url=img["src"] print img_url Just print out the src of the found images. imgs= soup.find_all('img', class_='_2di5p') for img in imgs: img_url=img["src"] ...

Python Web Scraping:无法从bs4元素中提取文本(Python Web Scraping: Unable to extract text from bs4 element)

尝试这个: import requests from bs4 import BeautifulSoup r = requests.get("http://cbcs.fastvturesults.com/student/1sp15me001") soup=BeautifulSoup(r.text,"html.parser") items = soup.find(class_="text-muted") print("{}\n{}".format(items.previous_sibling,ite...

麻烦用BS4刮痧网站(Trouble Scraping site with BS4)

文本使用JavaScript呈现。 首先使用dryscrape渲染页面 (如果你不想使用dryscrape,请参阅使用Python抓取Web页面 ) 然后,文本可以在呈现之后从页面上的不同位置(即已经渲染到的位置)被提取。 作为示例,此代码将从摘要中提取HTML。 import bs4 as bs import dryscrape url = ("http://programs.dsireusa.org/system/program/detail/284") session = dryscrap...

使用BS4获取属性名称而不是值(Getting attribute name rather than value with BS4)

您可以将find_all与谓词一起使用来缩小搜索范围,然后使用类似dict的索引访问该特定属性。 from bs4 import BeautifulSoup soup = BeautifulSoup(text, 'html5lib') items = soup.find_all('div', {'class' : 'item'}) for item in items: print(item['data-itemid']) 如果您希望进一步缩小搜索范围,可以在dict中添加更多谓词,如...

没有名为'bs4'的模块错误(No module named 'bs4' Error)

我真的没有看到用您提供的信息回答您的问题的明确方法,但似乎您没有正确安装bs4包... - 易于修复的方法 - 安装PyCharm: https ://www.jetbrains.com/pycharm/download/#section=windows 安装后,将解释器配置为使用最新版本的Python(从此处安装): https : //www.python.org/downloads/ 打开文件后,单击“文件>设置>项目解释器>全部显示(在下拉列表中)>添加(+)>添加本地”,然后选择已安装的...

AttributeError:'ResultSet'对象没有属性'previousSibling'BS4(AttributeError: 'ResultSet' object has no attribute 'previousSibling' BS4)

您正在搜索的图像没有siblings 。 你想要的(我认为)是让PARENT以前的兄弟形象。 例: from bs4 import BeautifulSoup import requests base_url = 'http://www.myfxbook.com/forex-economic-calendar' response = requests.get(base_url) soup = BeautifulSoup(response.content.decode('utf-8'), "h...

相关文章

更多

疯狂Android讲义

李刚编著的《疯狂Android讲义》全面地介绍了Android应用开发的相关知识,全书内容覆盖了And ...

Professional Android 4 Application Development

Developers, build mobile Android apps using Android ...

android 集成所有分享平台

注意: 本文介绍的是Share SDK 2.x版本的集成流程和注意事项,对于Share SDK 1.x ...

微信Android接入指南

注:本文为微信Android终端开发工具的新手使用教程,只涉及教授SDK的使用方法,默认读者已经熟悉I ...

Android开发权威指南.pdf 电子书下载

《Android开发权威指南》内容全面,不仅详细讲解了Android框架、Android控件、用户界面 ...

Android应用加入微信分享

一、申请你的AppID http://open.weixin.qq.com/ 友情提示:推荐使用ec ...

Android应用加入微信分享

一、申请你的AppID http://open.weixin.qq.com/ 友情提示:推荐使用e ...

android小知识之分享

在很多app上都有将某些内容进行分享,不错的功能。 首先是通过使用各个官方的SDK进行指定的分享,找到 ...

微信公众平台消息接口开发(25)URL关注链接

很多网友看到有人发布为微信信息中附带的连接,直接点击后可以链接到微信公众号介绍页面,可以直接加关注,询 ...

Android学习之 UI效果

探究Android的多分辨率支持以及各种类型图标尺寸大小 - CSDN 各种数字提醒控件-Androi ...

最新问答

更多

如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)

请尝试以下方法: $messages = $user->contact_messages()->paginate(10); Try the following: $messages = $user->contact_messages()->paginate(10);

linux的常用命令干什么用的

linux和win7不一样,win7都图形界面,都是用鼠标来操作打开,解压,或者关闭。而linux是没有图形界面的,就和命令提示符一样的一个文本框,操作linux里的文件可没有鼠标给你用,打开文件夹或者解压文件之类的操作都要通过linux常用命令。

由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)

它创建了这些视图: 'auth/login.blade.php', 'auth/register.blade.php', 'auth/passwords/email.blade.php', 'auth/passwords/reset.blade.php', 'layouts/app.blade.php', 'home.blade.php' 并修改这些文件: 'Http/Controllers/HomeController.php', 'routes/web.php' 如果使用--views

如何交换返回集中的行?(How to swap rows in a return set?)

您可以使用特殊的CASE表达式进行ORDER BY如下所示: SELECT * FROM table ORDER BY CASE id WHEN 3 THEN 8 WHEN 8 THEN 3 ELSE id END You can ORDER BY using a special CASE expression like this: SELECT * FROM table ORDER BY CASE id WHEN 3 THEN 8 WHEN 8 THEN 3 ELSE id END

在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)

我建议你制作一个新的TableView Cell,在这个newTableViewCell中,加载第2节中的所有单元格,然后为newTableViewCell提供边框。 但如果您不想这样做,那么您可以使用以下代码: @property(strong,nonatomic) CAShapeLayer* borderPath; -(void)viewDidLayoutSubviews{ [_borderPath removeFromSuperlayer]; UIView *viewToGiveBord

使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)

出于一些奇怪的原因,我现在发现了一个不同的问题, Boost.Spirit SQL语法/词法分析失败 ,其中提供了一些其他解决方案来进行空格跳过。 一个更好的! 以下是根据建议重新编写的示例代码: #include #include #include #include #include #incl

Java中的不可变类(Immutable class in Java)

1.如果我只有final变量的课程? 这会让你远离但不是全部。 这些变量的类型也需要是不可变的。 考虑一下 class MyImmutableClass { // final variable, referring to a mutable type final String[] arr = { "hello" }; // ... } 这允许有人做 myImmutableObject.arr[0] = "world"; 并有效地改变你的不可变类的对象。 此外,建议禁

WordPress发布查询(WordPress post query)

如果你想要在div中包含所有帖子: post_parent) { $myposts = get_posts('numberposts=10&tag=medical&order=DESC'); echo ' '; foreach ($myposts as $post): ?>

如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)

我不确定哪个是MySQL的正确答案,因为它本身还不支持IPv6地址格式(尽管“ WL#798:MySQL IPv6支持 ”表明它将在MySQL v6.0中,当前文档不支持)。 不过,你建议的人建议去2 * BIGINT,但要确保他们是UNSIGNED。 在IPv6的/ 64地址边界处有一种自然分割(因为/ 64是最小的网格块大小),这将与其很好地对齐。 I'm not sure which is the right answer for MySQL given that it doesn't y

是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)

您可以使用Object.keys和Array#find来获取匹配value的key 。 const letters = {a:'26',b:'25',c:'24',d:'23',e:'22',f:'21',g:'20',h:'19',i:'18',j:'17',k:'16',l:'15',m:'14',n:'13',o:'12',p:'11',q:'10',r:'9',s:'8',t:'7',u:'6',v:'5',w:'4',x:'3',y:'2',z:'1'}; function sw