Variable within another Python variable

0

I need to know if there is a certain text within my variable content, for example:

content = 
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="expires" content="mon, 27 sep 2018 14:30:00 GMT">
<title>Peri├│dico am | Detienen a dos por secuestro de una joven en 'Las Joyas' </title>
<meta http-equiv="content-language" content="es_MX" />
<meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, user-scalable=no" />
<meta charset="utf-8">

h = "charset"

I do not know how to do a conditional asking if H is within content

code:

import urllib2,cookielib

site= "https://www.am.com"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
       'Accept-Encoding': 'none',
       'Accept-Language': 'en-US,en;q=0.8',
       'Connection': 'keep-alive'}

req = urllib2.Request(site, headers=hdr)

try:
    page = urllib2.urlopen(req)
except urllib2.HTTPError, e:
    print e.fp.read()

content = page.read()
print content
    
asked by Martin Bouhier 27.12.2017 в 01:31
source

1 answer

0
import urllib2,cookielib

site= "http://labrujula24.com/noticias/2017/39864_Encontraron-a-dos-policias-durmiendo-adentro-de-un-patrullero-en-la-Ruta-3"
hdr = {'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
       'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
       'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
       'Accept-Encoding': 'none',
       'Accept-Language': 'en-US,en;q=0.8',
       'Connection': 'keep-alive'}

req = urllib2.Request(site, headers=hdr)

try:
    page = urllib2.urlopen(req)
except urllib2.HTTPError, e:
    print e.fp.read()

content = page.read()

"charset" in content
    
answered by 27.12.2017 в 01:39