首页
\
问答
\
如何在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 ...
-
用Python / BS4刮表(Scraping Table With Python/BS4)[2022-05-14]
在这种情况下的问题是“团队统计信息”表位于 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 ... -
使用BS4解析HTML表(Parsing HTML Tables with BS4)[2022-06-27]
我只用了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 ...
-
Python Web Scraping:无法从bs4元素中提取文本(Python Web Scraping: Unable to extract text from bs4 element)[2023-12-28]
尝试这个: 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 ... -
麻烦用BS4刮痧网站(Trouble Scraping site with BS4)[2023-08-18]
文本使用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'的模块错误(No module named 'bs4' Error)[2023-11-07]
我真的没有看到用您提供的信息回答您的问题的明确方法,但似乎您没有正确安装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 ...