- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
让我先声明一下,我知道在有这么多更好的工具的情况下,在 sed 中进行网页抓取是一个愚蠢的想法。我试着把这件事告诉我的老师,但他坚持要使用 sed 和 awk。
我的目标是抓取一个 Twitter 页面并返回所有推文。使用此代码:
sed -n '/<p class=\"TweetTextSize js-tweet-text tweet-text\" lang=\"en\" data-aria-label-part=\"0\">/,/<\/p>/p' $targ | sed 's/<[^>]\+>/ /g;s/^[ \t]*//;/^$/d'
On this URL到目前为止,我一直没有得到我想要的东西。
这是围绕推文的代码:
<p class="TweetTextSize js-tweet-text tweet-text" lang="en" data-aria-label-part="0">Where is our universe headed? Answer to it's death, not to worry <a href="/PaulMattSutter" class="twitter-atreply pretty-link js-nav" dir="ltr" data-mentioned-user-id="556263627" ><s>@</s><b>PaulMattSutter</b></a> explains. <a href="https://t.co/ig8KtQzwOI" rel="nofollow" dir="ltr" data-expanded-url="http://oak.ctx.ly/r/42bnj" class="twitter-timeline-link" target="_blank" title="http://oak.ctx.ly/r/42bnj" ><span class="tco-ellipsis"></span><span class="invisible">http://</span><span class="js-display-url">oak.ctx.ly/r/42bnj</span><span class="invisible"></span><span class="tco-ellipsis"><span class="invisible"> </span></span></a> <a href="https://t.co/kOy4jLCogk" class="twitter-timeline-link u-hidden" data-pre-embedded="true" dir="ltr" >pic.twitter.com/kOy4jLCogk</a></p>
现在,我只想从 <p class="TweetTextSize js-tweet-text tweet-text" lang="en" data-aria-label-part="0">
之间的页面抓取内容及其对应的</p>
然后我想过滤它,以便删除中间的所有标签(打开和关闭),这样它看起来像这样:
Where is our universe headed? Answer to it's death, not to worry @PaulMattSutter explains. http://oak.ctx.ly/r/42bnj pic.twitter.com/kOy4jLCogk
最佳答案
试试这个:
sed -n '/<p class="TweetTextSize js-tweet-text tweet-text" lang="en" data-aria-label-part="0">.*<\/p>/{s/<[^>]*>//g;p}' file
输出:
You’ve never seen Pluto like this! @NASANewHorizons returns sharpest views yet! Take a look: http://go.nasa.gov/1NxLViz pic.twitter.com/iK4OJKeLUE The world is filled with those who do nothing yet criticize. I love this @rickygervais motto: Go create! pic.twitter.com/m7zB8ucclT Can you see me waving? How to spot #Mars in the night sky: https://youtu.be/hv8hVvJlcJQ https://amp.twimg.com/v/9b945202-5a89-4efa-80ab-514a0c17a965 … We knew the first high-res images of Pluto would be good, but we didn't expect THIS good: http://ow.ly/Vvrvm pic.twitter.com/r8ZX4Z5tVt Toddler wears the most precious 'Monsters, Inc.' costume this world has ever seen http://on.mash.to/1HLrcMk pic.twitter.com/2PyuDW9yms Are you on your way to your @TMobile store, @ATT customers?! GO!! #UncarrierUnwrapped http://t-mo.co/1SzhOfb pic.twitter.com/0vNJbD2J4k 1 year ago today, @USNavy @ussanchorage recovered Orion in Pacific ocean after successful flight. pic.twitter.com/DKW00LzlC3 How Fallout 4 mastermind Todd Howard builds his epic dream worlds http://wrd.cm/1IILf8N pic.twitter.com/WUV98e6U62 23-year-old’s design collaboration tool Figma launches with $14M to fight Adobe http://tcrn.ch/1YPW8Pw pic.twitter.com/wVrZbfgBOc Here’s a list of questions investors will ask themselves after you pitch a company to them. http://kpcb.cc/b466b5b pic.twitter.com/zOJDOrq0na Blow your mind with this--ENJOY! (And check the SWEET video too)! http://www.nasa.gov/feature/new-horizons-returns-first-best-images-of-pluto … #PlutoFlyby pic.t Human gene editing is OK, but no designer babies—for now, summit concludes: http://ow.ly/VscSg #GeneEditSummit pic.twitter.com/UW6DKtQX4h NASA releases the highest resolution images ever taken of Pluto http://www.theverge.com/2015/12/4/9851162/nasa-new-horizons-pluto-photo-new-high-resolution?utm_campai A drone that finds you a parking space and then hovers in it to stop anyone else taking it first. The ubiquity of guns poses a much greater threat to Americans than terrorism http://bit.ly/1lbvPoQ By @Horganism pic.twitter.com/pdxvVqGS59 Scientist disinvited from speaking at conference because of her pregnancy http://ow.ly/Vvyam pic.twitter.com/FUAjaycIom Samsung agrees to pay Apple $548 million in settlement http://engt.co/1jEN28t pic.twitter.com/3DmmccJUgW World's first in-human gene-editing treatment will tackle hemophilia http://www.engadget.com/2015/12/03/worlds-first-in-human-CRISPR-hemophilia/ … pic.twitte Where is our universe headed? Answer to it's death, not to worry @PaulMattSutter explains. http://oak.ctx.ly/r/42bnj pic.twitter.com/kOy4jLCogk New Horizons just sent back the sharpest images possible of Pluto's surface. Drink it in http://www.wired.com/2015/12/new-horizons-just-sent-its-highest-res-image Get people to do what you want with these 11 clever psychological tricks: http://lifehac.kr/GZaSWhN pic.twitter.com/5rhWlVL9t0
关于linux - 使用 SED 进行网页抓取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34110472/
我需要一些有关 Sed 的帮助。我在 Windows 和 Mac OSX 上使用它。我需要 Sed 添加一个 每 4 行,在第一个 之后找到,并在 上停止这样做 我就是找不到办法做到这一点。每
我是一个管理很多网站的轮换团队的一员,我们继承了一个网站的一些特别糟糕的代码,我们正在彻底重新设计该网站。非常可怕的是,开发服务器上有一些链接将您带到实时服务器和旧域以及许多其他可怕的事情。 我一直在
我正在尝试在脚本中运行以下表达式以查找设备并在html文件中更改与该设备关联的字段之一。 sed -e "s/$OLDTEST/$TESTING/" -e "s/$CURRENTVALU/$NEWST
我正在尝试使用 sed 删除所有出现的 #ifdef _WIN32 #endif #ifdef 和 #endif 之间存在的所有内容都是空行。我使用 sed 的经验有限,我已经阅读了一些关于多行功能的
以下命令是什么意思: sed -e '/SUBCKT\ REDBK128S4_LC/,/ENDS/ d' $1 什么,代表? 最佳答案 如果指定两个地址,则指定执行命令的行范围。在您的 sed表达
我需要使用sed注释匹配行和其后的4行的帮助。 在文本文件中。 我的文本文件是这样的: [myprocess-a] property1=1 property2=2 property3=3 proper
我想要一个sed命令来完成以下任务: $ sed s'/:/ /g' sed s'/=/ /g' 也就是说,我想写 sed s'// /g' 并用空格替换=和:。 最佳答案 sed s'/[:=]/
我想在大文件中每隔30行插入一个字符串。我正在使用mini-sed,它不支持〜(波浪号)范围运算符。我正在寻找仅sed的解决方案。 最佳答案 该线程是如何使事情过于复杂的另一个示例。应该这样做: se
有人可以帮我吗? grep " 287 " file.txt | grep "HI" | sed -i 's/HIS/HID/g' sed: no input files 也尝试过 xargs gre
这个问题已经有答案了: How can I replace each newline (\n) with a space using sed? (43 个回答) 已关闭2 年前。 如何使用 sed 命
我们需要屏蔽信用卡号。屏蔽除最后 4 位数字以外的所有数字。我正在尝试使用 SED。由于信用卡号长度从 12 位到 19 位不等,我正在尝试编写正则表达式。以下代码将收到字符串。如果它包含形式为“CA
例如: sed 's@/lib\(64\)\?\(32\)\?/ld@/tools&@g' abc.txt 's@' 、 '(' 、 '\?' 、'&' 和 '@' 等含义是什么? 如何找到最合适
我们有一个进程可以使用包含 sed 的文件更改管道输入的命令。 我需要用变量值替换输入中的占位符,例如在一个 -e我可以运行的命令类型; $ echo "Today is XX" | sed -e "
这个问题在这里已经有了答案: Using different delimiters in sed commands and range addresses (3 个答案) 关闭1 年前。 我想问 2
是的,我搜索了该网站,但我认为我没有看到任何东西可以专门解决我无法克服的非常(我想很简单)的问题。 我正在上 Linux 类(class),有人问我这个问题: Use the sed command
我有一个看起来像这样的文件路径列表 abc/def/ghi/jl/r1/r2 abc/def/ghi/jl/r9/r11 abc/nyc/ghi/jl/r3/r4/r5 abc/nyc/ghi/jl/
我在这个文件中有这个文本: test.php $databases = array ( 'default' => array ( 'default' => array (
让我们考虑一个包含以下语句的 SQL 文件作为输入(即 myTable.sql): EXECUTE IMMEDIATE 'CREATE OR REPLACE PUBLIC SYNONYM ' || m
好的,谷歌搜索几分钟后,这似乎是在每行输出前加上 sed 前缀的常规方法 但是我得到一个我不明白的错误。 这是什么意思,我该如何解决? $ sed 's/^/#/' test.txt sed: -e
我有以下文件列表: r1 r2 10 r11 r99 我正在尝试替换 ls 输出中文件名中 r 之后的所有数字 我要找的结果: rA rA rA rA rA 使用下面的 sed 命令我可以匹配
我是一名优秀的程序员,十分优秀!