António Oliveira Posted May 2, 2017 at 09:35 PM Report #603920 Posted May 2, 2017 at 09:35 PM re.match( r'fileKey: "(.*).mp4"', html,re.MULTILINE) não consegue capturar nada. Mesmo usando qualquer padrão mais simples, a partir do momento em que use uma string suficientemente grande (copiada a partir de html e em substituição dela). Por exemplo: line ='href="//ajax.googleapis.com" rel="dns-prefetch"/><meta content="110253572394348" property="fb:pages"/> <title>Casa cheia em Madrid para ver e ouvir David Fonseca - Cultura - RTP Notícias</title><meta content="O músico português esteve em Espanha para apresentar o último álbum, totalmente cantado em português." name="description"/><meta content="cultura" name="section"/> <meta content="Casa cheia em Madrid para ver e ouvir David Fonseca" property="og:title"/>' mo = re.match( r'Madrid(.*)Fonseca', line) Mas já sou bem sucedido com: line ='href="//ajax.googleapis.com" rel="dns-prefetch"/><meta content="110253572394348" property="fb:pages"/>' mo = re.match( r'href(.*).com"', line) Como faço para lidar com este problema? # -*- coding: utf-8 -*- #import the library used to query a website from urllib.request import urlopen #specify the url rtp = "https://www.rtp.pt/noticias/cultura/casa-cheia-em-madrid-para-ver-e-ouvir-david-fonseca_v897602" #Query the website and return the html to the variable 'page' page = urlopen(rtp) #import the Beautiful soup functions to parse the data returned from the website from bs4 import BeautifulSoup #Parse the html in the 'page' variable, and store it in Beautiful Soup format soup = BeautifulSoup(page, "lxml") #Get the content as a string html = str(soup.html) #import the library used for regular expressions import re mo = re.match( r'fileKey: "(.*).mp4"', html,re.MULTILINE)
António Oliveira Posted May 2, 2017 at 10:32 PM Author Report #603922 Posted May 2, 2017 at 10:32 PM Já vi qual é o problema. Tenho que usar search() em vez de match().
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now