1.获取子标签: thr_msgs = soup.find_all('div',class_=re.compile('msg')) for i in thr_msgs: print(i) first = i.select('em:nth-of-type(1)') print(first) >>> <div class='\"msg\"'><em>佛山</em><em>1-3年&
今天有同学问如何用 JS 正则表达式获取一段文本中的超链接,并对超链接进行处理,想了几分钟,写了下面的代码: var re = /https?:\/\/[\w\.:~\-\d\/]+(?:\?[\w\d\-_&=%]+)?(?:#[^\s]+)?/i; 这个正则表达式处理这种类型的URL: protocol://host:port/path?param=value#xxoo 想法是好的,但总要测试通过才可以,随即又写了一段获取页面内所有带有 src, href 属性的代码: function g