标签: html-content-extraction

Python HTML抓取

这不是真的在刮,我只是想在网页中找到具有特定值的网址.例如:

<a class="myClass" href="/url/7df028f508c4685ddf65987a0bd6f22e">
Run Code Online (Sandbox Code Playgroud)

我想获得href值.关于如何做到这一点的任何想法?也许正则表达式?你能发布一些示例代码吗?我猜html抓取libs,比如BeautifulSoup,对于这个来说有点矫枉过正......

非常感谢!

html python regex screen-scraping html-content-extraction

3
推荐指数
2
解决办法
3794
查看次数

3
推荐指数
2
解决办法
3821
查看次数

使用BeautifulSoup基于内容值提取标记内容

我有一个以下格式的Html文档.

<p>&nbsp;&nbsp;&nbsp;1. Content of the paragraph <i> in italic </i> but not <b> strong </b> <a href="url">ignore</a>.</p>
Run Code Online (Sandbox Code Playgroud)

我想提取段落标记的内容,包括斜体和粗体标记的内容,但不包含锚标记的内容.此外,可能在开头忽略数字.

预期的输出是:段落的内容用斜体但不强.

最好的方法是什么?

此外,以下代码片段返回TypeError:类型为"NoneType"的参数不可迭代

soup = BSoup(page)
for p in soup.findAll('p'):
    if '&nbsp;&nbsp;&nbsp;' in p.string:
        print p
Run Code Online (Sandbox Code Playgroud)

谢谢你的建议.

python beautifulsoup html-content-extraction

3
推荐指数
1
解决办法
2654
查看次数

如何为html解析编写正则表达式?

我正在尝试为我的html解析器编写正则表达式.

我想匹配给定的属性(如一个html标记<div>class="tab news selected"),它包含一个或多个<a href>标签.正则表达式应该与整个标签(从<div></div>).我似乎总是得到"内存耗尽"错误 - 我的程序可能会将它可以找到的每个标记作为匹配的标记.

我正在使用boost regex库.

html c++ regex boost html-content-extraction

2
推荐指数
1
解决办法
4710
查看次数

如何使用RegEx从HTML中提取值?

给出以下HTML:

<p><span class="xn-location">OAK RIDGE, N.J.</span>, <span class="xn-chron">March 16, 2011</span> /PRNewswire/ -- Lakeland Bancorp, Inc. (Nasdaq:   <a href='http://studio-5.financialcontent.com/prnews?Page=Quote&Ticker=LBAI' target='_blank' title='LBAI'> LBAI</a>), the holding company for Lakeland Bank, today announced that it redeemed <span class="xn-money">$20 million</span> of the Company's outstanding <span class="xn-money">$39 million</span> in Fixed Rate Cumulative Perpetual Preferred Stock, Series A that was issued to the U.S. Department of the Treasury under the Capital Purchase Program on <span class="xn-chron">February 6, 2009</span>, thereby reducing Treasury's investment in the Preferred Stock to <span …
Run Code Online (Sandbox Code Playgroud)

regex text-extraction html-content-extraction

2
推荐指数
1
解决办法
1万
查看次数

如何使用本地html文件的samppipe?

我的本地磁盘上有一个html文件,并希望使用BoilerPipe从中提取文本.

来自ExtractorBase类的"getText"方法接受一个读者,所以我写道:

FileReader fr = new FileReader("D:/myHTMLfile");
System.out.println(ArticleExtractor.INSTANCE.getText(fr));
Run Code Online (Sandbox Code Playgroud)

但后来我得到一个指向第二行代码的错误.

任何线索?谢谢!

编辑:整个错误消息是:

Exception in thread "pool-1-thread-1" java.lang.NoClassDefFoundError: org/cyberneko/html/HTMLConfiguration
    at de.l3s.boilerpipe.sax.BoilerpipeHTMLParser.<init>(BoilerpipeHTMLParser.java:50)
    at de.l3s.boilerpipe.sax.BoilerpipeHTMLParser.<init>(BoilerpipeHTMLParser.java:41)
    at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
    at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
    at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:101)
    at neuromarket.BoilerPlateExtractor.run(BoilerPlateExtractor.java:42)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: org.cyberneko.html.HTMLConfiguration
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    ... 9 more
Exception in thread "pool-1-thread-2" java.lang.NoClassDefFoundError: org/cyberneko/html/HTMLConfiguration
    at de.l3s.boilerpipe.sax.BoilerpipeHTMLParser.<init>(BoilerpipeHTMLParser.java:50)
    at de.l3s.boilerpipe.sax.BoilerpipeHTMLParser.<init>(BoilerpipeHTMLParser.java:41)
    at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
    at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
    at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:101)
    at neuromarket.BoilerPlateExtractor.run(BoilerPlateExtractor.java:42)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
BUILD …
Run Code Online (Sandbox Code Playgroud)

java html-content-extraction boilerpipe

2
推荐指数
1
解决办法
3350
查看次数

如何使用 Linux 命令行以编程方式从网页中提取信息?

我需要从一长串历史日期中提取美元到另一种货币(例如欧元)的汇率。

www.xe.com网站提供了历史查询工具,使用详细的 URL,您可以获得特定日期的费率表,而无需填充Date:From:框。例如,URL http://www.xe.com/currencytables/?from=USD&date=2012-10-15给出了 2012 年 10 月 15 日当天美元兑其他货币的兑换率表。

现在,假设我有一个日期列表,我可以遍历列表并更改该 URL 的日期部分以获取所需的页面。如果我可以提取汇率列表,那么simplegrep EUR会给我相关的汇率(我可以用awk专门提取汇率)。

问题是,如何使用 Linux 命令行命令获取页面?我试过了,wget但没有成功。

如果不是 CLI,是否有一种简单而直接的方法来以编程方式执行此操作(即,与将日期复制粘贴到浏览器的地址栏相比所需的时间更少)?


更新1:

运行时:

$ wget 'http://www.xe.com/currencytables/?from=USD&date=2012-10-15'
Run Code Online (Sandbox Code Playgroud)

我得到一个文件,其中包含:

<HTML>
<HEAD><TITLE>Autoextraction Prohibited</TITLE></HEAD>
<BODY>
Automated extraction of our content is prohibited.  See <A HREF="http://www.xe.com/errors/noautoextract.htm">http://www.xe.com/errors/noautoextract.htm</A>.
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)

所以看起来服务器可以识别查询的类型并阻止wget. 有什么办法解决这个问题吗?


更新 2:

在阅读wget命令的响应和评论/答案后,我检查了网站的 ToS 并发现了这一条款:

You agree that you shall not:
...
f. use any automatic or manual process to collect, harvest, …
Run Code Online (Sandbox Code Playgroud)

html linux extract html-content-extraction

2
推荐指数
1
解决办法
1万
查看次数

用java从网页中读取源代码

我正在尝试从网页中读取源代码。我的Java代码是

import java.net.*;
import java.io.*;
import java.util.*;
import javax.swing.JOptionPane;

class Testing{
public static void Connect() throws Exception{


  URL url = new URL("http://excite.com/education");
  URLConnection spoof = url.openConnection();


  spoof.setRequestProperty( "User-Agent", "Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0; H010818)" );
  BufferedReader in = new BufferedReader(new InputStreamReader(spoof.getInputStream()));
  String strLine = "";


  while ((strLine = in.readLine()) != null){


   System.out.println(strLine);
  }

  System.out.println("End of page.");
 }

 public static void main(String[] args){

  try{

   Connect();
  }catch(Exception e){

  }
}
Run Code Online (Sandbox Code Playgroud)

当我编译并运行此代码时,它提供以下输出:

? I?%&/m?{J?J??t?$?@??????iG#)?*??eVe]f@????{???{???;?N'????\fdl??J??!?? ??~|?"~?$}?>???????4?????7N?????+??M?N???J?tZfM??G?j?? ??R??!?9??>JgE??Ge[????????W???????8?????? ?|8? ??????? ??ho????0????|?:--?|?L?U?????m?zt?n3??l\?w??O^f?G[?CG< ?y6K??gM?rg???y?E?y????h~????X???l=??Z?/????(?^O?UU6???? …

java html-content-extraction

2
推荐指数
1
解决办法
1万
查看次数

Beautifulsoup在表中获得价值

我试图刮 http://www.co.jefferson.co.us/ats/displaygeneral.do?sch=000104 并获得"所有者姓名"我的工作但是真的很难看而且不是最好的我确定,所以我正在寻找更好的方法.这是我有的:

soup = BeautifulSoup(url_opener.open(url))            
x = soup('table', text = re.compile("Owner Name"))
print 'And the owner is', x[0].parent.parent.parent.tr.nextSibling.nextSibling.next.next.next
Run Code Online (Sandbox Code Playgroud)

相关的HTML是

<td valign="top">
    <table border="1" cellpadding="1" cellspacing="0" align="right">
    <tbody><tr class="tableheaders">
    <td>Owner Name(s)</td>
    </tr>

    <tr>

    <td>PILCHER DONALD L                         </td>
    </tr>

    </tbody></table>
</td>
Run Code Online (Sandbox Code Playgroud)

哇,有很多关于beautifulsoup的问题,我看了看他们但找不到帮助我的答案,希望这不是一个重复的问题

python screen-scraping beautifulsoup html-content-extraction

1
推荐指数
1
解决办法
4235
查看次数

从字符串中提取URL的特定部分

我需要使用PHP仅提取URL的一部分,但我正在努力达到提取应该停止的设定点.我使用正则表达式从更长的字符串中提取整个URL,如下所示:

$regex = '/\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i';
preg_match_all($regex, $href, $matches);
Run Code Online (Sandbox Code Playgroud)

结果是以下字符串:

http://www.cambridgeenglish.org/test-your-english/&amp;sa=U&amp;ei=a4rbU8agB-zY0QWS_IGYDw&amp;ved=0CFEQFjAL&amp;usg=AFQjCNGU4FMUPB2ZuVM45OoqQ39rJbfveg
Run Code Online (Sandbox Code Playgroud)

现在我想只提取这一点http://www.cambridgeenglish.org/test-your-english/.我基本上需要摆脱从头&amp开始的一切.

任何人都知道如何实现这一目标?我是否需要运行另一个正则表达式,还是可以将其添加到初始正则表达式?

php regex html-content-extraction

1
推荐指数
1
解决办法
391
查看次数