美丽的汤findall与排除groupon

时间:2018-06-07 23:42:41

标签: python regex web-scraping beautifulsoup data-science

我正在报废报纸,以获取<>下的通知正文。 p为H.标签 我把所有的"<< p>"标签,但我需要排除"< p为H. < div class =" L video">"标记因为在该标记下HTML包含我不需要的信息。 一个选项是使用正则表达式,所以我在https://regexr.com/中测试了排除组(< p>)[^(< p>< div)]并且显然工作正常,但我无法做到在我的代码中使用Beautiful Soup正常工作。

url = 'https://www.lanacion.com.ar/2141182-mundial-rusia-2018-gritos-el-temor-de-messi-y-una-marcha-atras-imparable-las-razones-detras-de-otro-dia-de-furia-en-la-seleccion'
resp = requests.get(url)
excl="<p> <div"
soup = BeautifulSoup(resp.text, 'html.parser')
body=soup.findAll('article',{'floatFix'})
for p in body:
    text = p.find_all("p")
    for p in text:
        print(p.text)

0 个答案:

没有答案