for name_elem, fcode_elem in zip(soup.find_all('name'), soup.find_all('fcode')):
writer.writerow({'Name': name_elem.get_text(), 'FCode': fcode_elem.get_text()})
def to_list(string):
"""String to list"""
return [phrase[2:].strip() for phrase in string.split("\n")][:-1]
y = to_list(a)
x = to_list(b)
import re
foo = '1. 4x Apples. \n2. 5x Bananas \n3. 6x Oranges\n4. 3x Pears\n'
bar = '1. Ice cream \n2. Rice \n3. Flour\n4. Cola\n'
def to_list(s):
return re.findall(r'\d+\.\s(.+?)(?=\s?\n)', s)
to_list(foo)
# ['4x Apples.', '5x Bananas', '6x Oranges', '3x Pears']
to_list(bar)
# ['Ice cream', 'Rice', 'Flour', 'Cola']
import re
a = "1. 4x Apples. \n2. 5x Bananas \n3. 6x Oranges\n4. 3x Pears\n"
b = "1. Ice cream \n2. Rice \n3. Flour\n4. Cola\n"
def to_list(data):
return [x.strip() for x in re.findall('\d+\.(.*)\n', data)]
y = to_list(a)
x = to_list(b)
print(y)
print(x)
import re
pattern = r'Model:.*|UPC:.*'
text = '''12" Non-Stick Skillet
with Helper Handle
Model: FCT22-30HNS
UPC: 086279034182
Case Pack: 4
5½ Qt. Sauté Pan with Cover
Model: FCT33-28H
UPC: 086279034038
Case Pack: 4
8" Skillet
Model: FCT22-20
UPC: 086279034007'''
print(re.findall(pattern, text))
['Model: FCT22-30HNS ', 'UPC: 086279034182 ', 'Model: FCT33-28H ', 'UPC: 086279034038 ', 'Model: FCT22-20 ', 'UPC: 086279034007']
page_content = []
page_text = '''
12" Non-Stick Skillet
with Helper Handle
Model: FCT22-30HNS
UPC: 086279034182
Case Pack: 4
5½ Qt. Sauté Pan with Cover
Model: FCT33-28H
UPC: 086279034038
Case Pack: 4
8" Skillet
Model: FCT22-20
UPC: 086279034007
'''
for line in page_text.splitlines():
if 'Model:' in line:
page_content.append(line)
print(page_content)
['Model: FCT22-30HNS ', 'Model: FCT33-28H ', 'Model: FCT22-20 ']
var str1 = 'Зеленая поляна';
re1='ная';
re2='яна';
var str_new = str1.replace(re1, 'ную');
var str_new=str_new.replace(re2,'яну');