Mahmoud Abdel-Fattah wrote:
Hello,
I'm coming from PHP background ant totally new to Python, I just
started using scrapy, but has some generic question in python.
1. How can I write the following code in easier way in Python ?
if len(item['description']) > 0:
item['description'] =
On Sun, Apr 15, 2012 at 9:00 AM, MRAB wrote:
> re.match(...) returns either a match object or None. In a condition, a
> match object always evaluates as True and None always evaluates as
> False.
Yes, should have clarified that. It's a deliberate feature of the re
module that you can do this. Ver
On 14/04/2012 23:45, Chris Angelico wrote:
On Sun, Apr 15, 2012 at 8:41 AM, Mahmoud Abdel-Fattah
wrote:
item['author_brand'] = author_brand.group(2) if type(author_brand) != None
else ''
Almost there! :)
None is a singleton, not a type; you don't need to check
type(author_brand) but rathe
On Sun, Apr 15, 2012 at 8:41 AM, Mahmoud Abdel-Fattah
wrote:
> item['author_brand'] = author_brand.group(2) if type(author_brand) != None
> else ''
Almost there! :)
None is a singleton, not a type; you don't need to check
type(author_brand) but rather its identity. Use "author_brand is not
None"
Thanks ChrisA a lot.
I just tried what you said, but I got an error, here's what I tried :
item['name'] = hxs.select('//div[@id="center-main"]/h1/text()').extract()[0]
author_brand = re.match(r'^[.*] - (.*)$', item['name'], re.I|re.S|re.M)
item['author_brand'] = author_brand.group(2) if type(autho
:
> 1. How can I write the following code in easier way in Python ?
> if len(item['description']) > 0:
> item['description'] = item['description'][0]
> else:
> item['description'] = ''
Assuming item['description'] is a string, all you need is
>>> item['description
On Sun, Apr 15, 2012 at 8:16 AM, Mahmoud Abdel-Fattah
wrote:
> Hello,
>
> I'm coming from PHP background ant totally new to Python, I just started
> using scrapy, but has some generic question in python.
>
> 1. How can I write the following code in easier way in Python ?
> if len(item['description
Hello,
I'm coming from PHP background ant totally new to Python, I just started
using scrapy, but has some generic question in python.
1. How can I write the following code in easier way in Python ?
if len(item['description']) > 0:
item['description'] = item['description'][0]