简体   繁体   English

我在Unix脚本中使用grep从html文件中得到了一行,但是我不知道如何使用sed提取文本

[英]i got line from html file using grep in unix script, but i can't figure out how to extract text using sed

i'm making a shell script that shows title and an artist of a song that is played on the radio. 我正在制作一个shell脚本,显示标题和电台播放的歌曲的艺术家。 i got html file and i found the line that i needed, using grep, but can't figure out how to extract the text that i need. 我得到了html文件,并使用grep找到了所需的行,但无法弄清楚如何提取所需的文本。 the line that i got is 我得到的是

<div class="n Title">title, different every time </div><div class=n Artist">artist that changes also</div> 

how do i extract the title and the artist using unix commands? 如何使用Unix命令提取标题和艺术家? i have tried many ways but it didn't work properly. 我已经尝试了许多方法,但是无法正常工作。

grep -Po 'Title">\K[^<]*'

gives you title, same idea you can get the Artist. 给您标题,您可以获得艺术家的相同想法。 but keep in mind, using regex to "parse" xml/html is risky, for example, the website change the html source, make this in separated lines... or they add some other attributes, or add some other css classes after Title ... 但请记住,使用正则表达式来“解析” xml / html是有风险的,例如,网站更改html源,将其分隔成行...或者它们添加一些其他属性,或在Title之后添加一些其他CSS类...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用sed,awk或grep从HTML表格单元格中提取数据? - How can I extract data from HTML table cells using sed, awk, or grep? 如何使用c ++从HTML提取文本? - How can I extract text from HTML using c++? 使用 sed 或 grep 从具有特定 id 的 html 标签之间提取文本 - extract text from between html tags with specific id using sed or grep 我不知道如何将它们放在同一行 - I can't figure out how to put them on the same line 我无法弄清楚如何将这个表放在中心[HTML - Gumby] - I can't figure out how to center this table [HTML - Gumby] 我不知道如何使用 CSS 和 HTML 将每个 div 元素的单词放在每边的中间 - I can't figure out how to place the words for each div element in the middle of each side using CSS and HTML 如何使用HTML :: Parser提取标签之间的文本? - How can I extract text between tags using HTML::Parser? 在C#中,如何从使用webproxy.load()获得的HTML页面中解析出一个URL? - In C#, how can I parse out a url from a html page that I have got using webproxy.load()? 使用 Python 3.7 和 Selenium,我不知道如何解决我的代码中的视口元素问题 - Using Python 3.7 and Selenium, I can't figure out how to troubleshoot my code for out of Viewport elements 如何使用Perl的HTML :: TableExtract从HTML文件中提取带有标题名称的特定列 - How can I extract specific columns with header names from an HTML file using Perl's HTML::TableExtract
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM