首页 \ 问答 \ 如何在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)

如何在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

相关问答

更多
  • 您可以使用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) events = ...
  • 对我来说,在这里使用任何类型的网页抓取似乎都没有必要。 由于无论如何都可以将数据作为文件下载,因此通过解析需要通过报废来表示数据,这是不够的。 相反,您可以下载数据并将其读入熊猫数据框。 您需要安装熊猫,以防万一您安装了Anaconda,您的计算机上可能已经安装了它,否则您可能需要下载Anaconda并安装pandas:conda install pandas 有关安装熊猫的更多信息 有了熊猫,您可以直接从Excel表格中读取数据: import pandas as pd df = pd.read_exce ...
  • 在这种情况下的问题是“团队统计信息”表位于 HTML源代码中的注释内 ,您可以使用requests下载该注释 。 找到注释并使用BeautifulSoup将其解析为“汤”对象: import requests from bs4 import BeautifulSoup, NavigableString url = 'http://www.pro-football-reference.com/boxscores/201602070den.htm' page = requests.get(url, heade ...
  • 我只用了8个小时左右就知道了。 学习很有趣。 谢谢Kevin的帮助! 它现在包含将已删除数据输出到csv文件的代码。 接下来是获取该数据并过滤掉某些位置.... 这是我的代码: import urllib2 from bs4 import BeautifulSoup import csv url = ('http://nflcombineresults.com/nflcombinedata.php?year=2000&pos=&college=') page = urllib2.urlopen(url) ...
  • 只需打印出找到的图像的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"] prin ...
  • 尝试这个: 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,items.te ...
  • 文本使用JavaScript呈现。 首先使用dryscrape渲染页面 (如果你不想使用dryscrape,请参阅使用Python抓取Web页面 ) 然后,文本可以在呈现之后从页面上的不同位置(即已经渲染到的位置)被提取。 作为示例,此代码将从摘要中提取HTML。 import bs4 as bs import dryscrape url = ("http://programs.dsireusa.org/system/program/detail/284") session = dryscrape.Ses ...
  • 您可以将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包... - 易于修复的方法 - 安装PyCharm: https ://www.jetbrains.com/pycharm/download/#section=windows 安装后,将解释器配置为使用最新版本的Python(从此处安装): https : //www.python.org/downloads/ 打开文件后,单击“文件>设置>项目解释器>全部显示(在下拉列表中)>添加(+)>添加本地”,然后选择已安装的Pytho ...
  • 您正在搜索的图像没有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'), "html.p ...

相关文章

更多

最新问答

更多
  • Runnable上的NetworkOnMainThreadException(NetworkOnMainThreadException on Runnable)
  • C ++ 11 + SDL2 + Windows:多线程程序在任何输入事件后挂起(C++11 + SDL2 + Windows: Multithreaded program hangs after any input event)
  • AccessViolationException未处理[VB.Net] [Emgucv](AccessViolationException was unhandled [VB.Net] [Emgucv])
  • 计算时间和日期差异(Calculating Time and Date difference)
  • 以编程方式标签NSMutableAttributedString swift 4(Label NSMutableAttributedString programmatically swift 4)
  • C#对象和代码示例(C# objects and code examples)
  • 在python中是否有数学nCr函数?(Is there a math nCr function in python? [duplicate])
  • 检索R中列的最大值和第二个最大值的行名(Retrieve row names of maximum and second maximum values of a column in R)
  • 给定md5哈希时如何查找特定文件(How to find specific file when given md5 Hash)
  • Python字典因某些原因引发KeyError(Python Dictionary Throwing KeyError for Some Reason)
  • 如何让Joomla停止打开新标签中的每个链接?(How do I get Joomla to stop opening every link in a new tab?)
  • DNS服务器上的NS记录不匹配(Mismatched NS records at DNS server)
  • Python屏幕捕获错误(Python screen capture error)
  • 如何在帧集上放置div叠加?(How to put a div overlay over framesets?)
  • 页面刷新后是否可以保留表单(html)内容数据?(Is it possible to retain the form(html) content data after page refreshed?)
  • 使用iTeardownMyAppFrame和iStartMyAppInAFrame在OPA5测试中重新启动应用程序超时(Restart app within OPA5 test using iTeardownMyAppFrame and iStartMyAppInAFrame timed out)
  • 自动拆分文本内容到列(Automatically splitting text content into even columns)
  • 在r中的循环中将模型名称分配给gbm.step(assigning model names to gbm.step in loop in r)
  • 昆明哪里有电脑等级考试二级C培训?
  • C ++模板实例化,究竟是什么意思?(C++ template instantiation, what exactly does it mean?)
  • 帮助渲染来自fields_for的部分内容(Help to render a partial from fields_for)
  • 将url.action作为json对象返回mvc(return url.action as json object mvc)
  • 使用.BAT中的.application文件类型运行ac#Console App(Run a c# Console App with .application file type from a .BAT)
  • 将bindingRedirect添加到.Net标准库(Adding a bindingRedirect to a .Net Standard library)
  • Laravel版本升级会影响您的控制器吗?(Laravel version upgrade affects your controller?)
  • imaplib.error:命令SEARCH在状态AUTH中非法,只允许在SELECTED状态(imaplib.error: command SEARCH illegal in state AUTH, only allowed in states SELECTED)
  • 如何在eclipse debug impala前端
  • 如何通过Ajax API处理多个请求?(How to handle multiple requests through an Ajax API? [closed])
  • 使用Datetime索引来分析数据框数据(Using Datetime indexing to analyse dataframe data)
  • JS 实现一个菜单效果