Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'string.': 0.05; 'modify': 0.07; 'output,': 0.09; 'sanity': 0.09; 'itself.': 0.14; 'check.': 0.16; 'code?': 0.16; 'command,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'somehow.': 0.16; 'stdout': 0.16; 'subject:when': 0.16; 'urllib': 0.16; 'skip:# 20': 0.16; 'wrote:': 0.18; 'looked': 0.18; 'all,': 0.19; 'bit': 0.19; 'seems': 0.21; 'code,': 0.22; 'import': 0.22; 'rules': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'filtering': 0.24; 'replace': 0.24; 'tells': 0.24; "haven't": 0.24; 'source': 0.25; 'right.': 0.26; 'least': 0.26; 'code:': 0.26; 'header:In-Reply-To:1': 0.27; 'appear': 0.29; 'michael': 0.29; 'am,': 0.29; "doesn't": 0.30; "i'm": 0.30; 'code': 0.31; 'getting': 0.31; "skip:' 10": 0.31; 'object.': 0.31; 'prints': 0.31; 'though.': 0.31; 'supposed': 0.32; 'run': 0.32; 'text': 0.33; 'comment': 0.34; 'maybe': 0.34; 'could': 0.34; 'subject:with': 0.35; 'skip:u 20': 0.35; 'but': 0.35; 'add': 0.35; 'doing': 0.36; 'method': 0.36; 'should': 0.36; 'skip:o 20': 0.38; 'displays': 0.38; 'filter': 0.38; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'rather': 0.38; 'does': 0.39; 'bad': 0.39; 'itself': 0.39; 'sure': 0.39; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'skip:u 10': 0.60; "you're": 0.61; 'provide': 0.64; 'header:Reply-To:1': 0.67; 'bothered': 0.68; 'reply-to:no real name:2**0': 0.71; 'glance': 0.84; 'reply- to:addr:python.org': 0.84; 'subject:try': 0.84; 'thing,': 0.91 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.1 cv=d+zMl3TE c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=5FYZ9MsUIQAA:10 a=dmvUA2QvH3IA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=vq-ifTFmnXYA:10 a=vnREMb7VAAAA:8 a=K46NZOIYWJgCV6_xMDgA:9 a=QEXdDO2ut3YA:10 X-AUTH: mrabarnett:2500 Date: Sun, 22 Dec 2013 20:28:21 +0000 From: MRAB User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.2.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: BLANK PAGE when i try Filtering Adsense with abpy References: <52B72AA7.4050609@gmail.com> In-Reply-To: <52B72AA7.4050609@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: python-list@python.org List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1387744110 news.xs4all.nl 2977 [2001:888:2000:d::a6]:38364 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:62551 On 22/12/2013 18:08, Michael Torrie wrote: > On 12/22/2013 10:20 AM, em rexhepi wrote: >> When I use my code it just displays nothing >> >> My code: >> #!/usr/local/bin/python3.1 >> >> import cgitb;cgitb.enable() >> >> import urllib.request >> response = urllib.request.build_opener() >> response.addheaders = [('User-agent', 'Mozilla/5.0')] >> response = urllib.request.urlopen("www.youtube.com";) >> >> html = response.read() >> >> from abpy import Filter >> with open("easylist.txt") as f: >> f = Filter(file('easylist.txt')) >> f.match(html) > > What happens when you comment out the above four lines? Does the web > page print without the filtering? Just as a sanity check. My hunch is > that html has no data in it. > > Also what is "f.match(html)" supposed to return? Is it supposed to > mutate html (seems unlikely) or does it return something? Looking at the > source code, match() does not return anything, but prints to stdout, > which is weird, but at least that tells us that it doesn't actually > change the html object. > >> print("Content-type: text/html") >> print() >> print (html) > > I'm not sure you're doing this right. adpy seems a bit goofy, but since > f.match() does not appear to change html at all, you should get the same > html out that urllib grabbed. So if you're not getting any output, that > means you're not getting the original html somehow. Also if f.match() > is doing its thing, I don't think you want to print out html after the > command, because f.match itself is printing to stdout itself. > > Have you looked over the adpy source code? I haven't bothered to run > it, but a glance through the code would seem to indicate that it doesn't > actually do the filtering at all, but rather just prints out the rules > that the html code you provide would match. I bet you could modify it > to do filtering though. Maybe add a method that uses rule.sub to > replace the bad text with an empty string. > The urlopen call also contains a stray semicolon.