Kemandirian spesies ialah keupayaan haiwan dan tumbuhan untuk mengekalkan spesiesnya bagi mengelakkan kepupusan.
Ciri dan tingkah laku khas haiwan untuk melindungi diri daripada musuh seperti:
(i) Memutuskan anggota badan;
(ii) Menyembur dakwat hitam;
(iii) Mempunyai mata palsu.
Galakkan penggunaan TMK untuk membuat pemerhatian pelbagai ciri dan tingkah laku khas haiwan untuk melindungi diri.
let's say that i have this text and i save it to database , but when i tried to pull it out from database , it just show everything in a single line , what's is the best way to keep the original format ?
You can change all \n characters to <br> and then upload to your DB.
When you fetch your data then you can convert all the <br> tags to \n character.
let x = `Kemandirian spesies ialah keupayaan haiwan dan tumbuhan untuk mengekalkan spesiesnya bagi mengelakkan kepupusan.
Ciri dan tingkah laku khas haiwan untuk melindungi diri daripada musuh seperti:
(i) Memutuskan anggota badan;
(ii) Menyembur dakwat hitam;
(iii) Mempunyai mata palsu.
Galakkan penggunaan TMK untuk membuat pemerhatian pelbagai ciri dan tingkah laku khas haiwan untuk melindungi diri.`;
let withBR = x.replace(/\n/gm, "<br>");
console.log("Upload To DB \n\n");
console.log(withBR);
// Upload To The DB
// ----------------------------------------------------------
// On Fetch Starts
let originalText = withBR.replace(/\<br\>/gm, "\n")
console.log("Original Text \n\n");
console.log(originalText);
Hope it helps.
Related
Sumbangan Data lokasi di sumbangkan Hasil dari aplikasi Terlalu gesa untuk buat sumbangan. Bila ada pergi Shopping complex .bila sudah balik , report tempat shopping kompleks itu kena really pada aplikasi report . sekarang data chache lokasi saya semaking besar saiz.update setiap bulan. Data beli pun tidak mampu untuk guna bulan depan. Tak sampai hujung bulan internet habis hanya Update PlayStore saja.
Hy,
I don't know how to send email as html. I try every example that can i find but i don't know how to implement in my code. When it's arive in mail show all the html not only the the message. Please help me to implement send as html format in my code below. Thank you
def email(request):
campanii = Campanie.objects.order_by('-pub_date')
if request.method == 'POST':
form = EmailLoginForm(request.POST)
if form.is_valid():
email = form.cleaned_data['email'].lower()
user = UserVot.objects.filter(email=email).first()
if user is None: # daca userul nu exista cu acea adresa de email
messages.error(request, "adresa de email nu este corecta sau valida")
return render(request, 'loginvot/email.html', {'form' : form, 'campanii':campanii , 'error_message' : "adresa de email nu este corecta sau valida"} )
link += sesame.utils.get_query_string(user)
user.email_user(
subject="Link vot",
message="""\
<html >
<head>
<meta charset="UTF-8">
</head>
<body>
<p> Salutare, <h4>{{user.username}}</h4></p><br>
<p>Acceseaza link-ul de mai jos pentru a intra in sectiunea de vot "Ambasadorii Valorilor Profi"</p><br>
{{link}}
</body>
</html>
"""
)
return render(request, 'loginvot/email.html', {'campanii':campanii , 'error_succes' : "in maximum 1 minut vei primi pe adresa de email completata un link de accesare sesiune de vot"} )
context = {'form' : EmailLoginForm, 'campanii' : campanii}
return render(request, 'loginvot/email.html', context)
The solution turned out to be much simpler than I anticipated. I put the email message in a separate file (template_mail.html) and i use funtion render_to_string then in user.email_user I added html_message wich take that template_mail. This is how the code now looks and works.
template_mail = render_to_string ('loginvot/template_email.html', {'user' : user, 'link' : link } )
user.email_user(
subject='Link vot Ambasadorii valorilor Profi',
message=f"""some message""",
html_message = template_mail
)
I am trying to scrape a website: www.gall.nl in order to create a database of all wines that are sold on this platform. I have the following code:
import requests
from bs4 import BeautifulSoup
URL = 'https://www.gall.nl/wijn/'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
mydivs = soup.find_all("div", {"class": "c-product-tile"})
print(len(mydivs))
first_wijn = mydivs[0]
print(first_wijn)
result = first_wijn.find()
So, this provides 12 results, which is correct.
Printing the first result provides the following:
<div class="c-product-tile" data-product='{"name":"Faustino V Rioja Reserva","id":"143561","currencyCode":"EUR","price":13.99,"discount":0,"brand":"Faustino","category":"Wijn","variant":"75CL","list":"productoverzicht","position":1,"dimension13":"2","dimension37":"Ja"}' itemprop="item" itemscope="" itemtype="https://schema.org/Product" js-hook-product-tile="">
<meta content="143561" itemprop="sku">
<meta content="8410441412065" itemprop="gtin8">
<meta content="Faustino" itemprop="brand">
<div class="product-tile__header">
<div class="product-tile__category-label">
<div class="m-product-taste-tooltip">
<span aria-label="Classic Red" class="a-tooltip-trigger" data-content="Stevig & Ferm" data-placement="bottom-start" js-hook-tooltip="">
<div class="tooltip-trigger__icon product-taste-tooltip__icon u-taste-profile-icon classic-red-red
....
<input class="add-to-cart-url" type="hidden" value="/on/demandware.store/Sites-gall-nl-Site/nl_NL/Cart-AddProduct"/>
</div>
</meta></meta></meta></div>
And I'm interested in getting the data from the first line:
<div class="c-product-tile" data-product='{"name":"Faustino V Rioja Reserva","id":"143561","currencyCode":"EUR","price":13.99,"discount":0,"brand":"Faustino","category":"Wijn","variant":"75CL","list":"productoverzicht","position":1,"dimension13":"2","dimension37":"Ja"}' itemprop="item" itemscope="" itemtype="https://schema.org/Product" js-hook-product-tile="">
In order to get the name, price and brand.
Can somebody help me with retrieving these data?
Use beautifulsoup's .attrs.get to get the data-product from the div
Then, convert to JSON to read desired values.
import json
import requests
from bs4 import BeautifulSoup
URL = 'https://www.gall.nl/wijn/'
page = requests.get(URL)
soup = BeautifulSoup(page.content, 'html.parser')
# Get all products
mydivs = soup.find_all("div", {"class": "c-product-tile"})
# Loop through each product
for div in mydivs:
# Get data-product
product = div.attrs.get("data-product", None)
# Convert string to json
jsonProduct = json.loads(product.encode('utf-8').decode('ascii', 'ignore'))
# Show name - brand - price
print('{0:<40} {1:<20} {2:>10}'.format(
jsonProduct['name'],
jsonProduct['brand'],
jsonProduct['price']
))
Using the format() to create 3 columns, the above code produces the following output:
Faustino V Rioja Reserva Faustino 13.99
Mucho Ms Tinto Mucho Mas 5.99
Cantina di Verona Valpolicella Ripasso Terre Di Verona 11.99
Villa Jeantel Villa Jeantel 8.99
Ondarre Rioja Reserva Ondarre 13.59
Valdivieso Chardonnay Valdivieso 5.99
Domaine Lamourie Ros Domaine Lamourie 7.99
Oveja Negra Chardonnay Viognier Oveja Negra 6.59
La Palma Merlot La Palma 6.59
Alamos Chardonnay Alamos 8.99
Les Hautes Pentes ros Les Hautes Pentes 7.99
Piccini Memoro Rosso Piccini 7.29
I am using angular's ng-bind-html to bind this text to page:
Ale
skoro nikdy sa nepozeráme na priemerné produkty s údivom, že nie sú skvelé.
Priemerné služby a produkty robia to, čo sa od nich očakáva. Nastavili ale
latku tak nízko, že skoro ani nemá cenu urobiť kvôli ním pár krokov navyše, aby
ste si ich kúpili.<div><br></div><div><br></div><div>Prečo
nie je každé jedlo v reštaurácii skvelou kúpou za svoju cenu? Vyzerá to, ako by
sme ochotne brali všetko viac menej zlé za prijateľné, s výnimkou prípadov, keď
daný produkt, služba alebo firma nestoja úplne za nič.</div><div><br></div><div><br></div><div>Vyzvite priemernosť vo
vašej firme na súboj. Pretože presne takýto pohľad priemernosti na vás, môžu
mať aj vaši zákazníci.</div>
so you can see it contains various html markups encoded characters.
ng-data-bind handles this very correctly so the text is readable on the page.
However when I use $sanitize for this text to filter the html characters out, I'm getting this:
Ale
skoro nikdy sa nepozeráme na priemerné produkty s údivom, že nie sú skvelé.
Priemerné služby a produkty robia to, čo sa od nich očakáva. Nastavili ale
latku tak nízko, že skoro ani nemá cenu urobiť kvôli ním pár krokov navyše, aby
ste si ich kúpili.<div><br></div><div><br></div><div>Prečo
nie je každé jedlo v reštaurácii skvelou kúpou za svoju cenu? Vyzerá to, ako by
sme ochotne brali všetko viac menej zlé za prijateľné, s výnimkou prípadov, keď
daný produkt, služba alebo firma nestoja úplne za nič.</div><div><br></div><div><br></div><div>Vyzvite priemernosť vo
vašej firme na súboj. Pretože presne takýto pohľad priemernosti na vás, môžu
mať aj vaši zákazníci.</div>
so how can I mimic ng-bind-html inside my controller to clear the text and use it further?
EDIT: to me more clear, I don't need to bind this text to the view. This already works. I need to work with the text in controller's logic so I just need to clean it and use it further.
$sce.trustAsHtml() should be used.
HTML:
<td ng-bind-html="mData.data | unsafe"></td>
JS:
mOverview.controller('appController', function ($scope, $sce) {
$scope.mData = [
{
'data': 'your data'
}
];
});
mOverview.filter('unsafeFilter', function($sce) {
return function(val) {
return $sce.trustAsHtml(val);
};
});
To be honest, this is my first time using asp.net web api and Razor.
I received an asp.net web api solution which uses itextSharp to generate a pdf.
The pdf is generated, but it is showing html tags that were sent with the content via jquery and JSON.
This is how it looks in PDF:
<div class="nf-filler-control-border"><div class="nf-filler-control-inner"><div class="ms-r
testate-field"><div
class="ExternalClassD88FE0C0B2A64B1797917A506C26ACA2"><div
class="ExternalClassAD6BB90065794E90B1097577B8697812">Aantal genodigden: 19</div><div
class="ExternalClassAD6BB90065794E90B1097577B8697812">Aantal aanwezig: 15</div><p
class="ExternalClassAD6BB90065794E90B1097577B8697812">Aantal ziek/verlof: 3</p><div
class="ExternalClassAD6BB90065794E90B1097577B8697812"><ol><li>Bij veiligheidsrondgang uitgevoerd op 02/04/13. Veel
gereedschap ligt niet op hun plaats, is onbeheerd achtergelaten, ligt in fietskarren, en zijn bovendien niet ingeschreven in
het register; kasten staan open, ladders niet afgesloten.</li><li>Persoonlijk werkgereedschap blijft gewoon liggen zelf
heeft men de dag erna verlof. = rommel.</li><li>Bij controle stekkers verleng kabels zien we dat de trekontlasting niet
correct gebruikt wordt en dat de insnijdingen te groot zijn. Zie foto's.</li>
<li>Alle communicatie (ziektebriefjes, KV,.....)met HR is nu naar Interleuvenlaan 27A - 3001 Herverlee
(achterzijde personeelsbadge)</li></ol></div></div></div></div></div>
this is the piece of code that displays data which is sent via jquery's ajax function: #Model.Description
And this is where the Razor engine parses the html template: return Razor.Parse(template, model);
Anyone has got any idea how to show the content properly inside the pdf without showing up the html tags on the document?
the html table shows fine, only the data displayed by #Model.Description does not show correctly.
this is the code:
private static string GetReport(ToolBoxMeeting tm)
{
var config = new TemplateServiceConfiguration
{
BaseTemplateType = typeof (HtmlTemplateBase<>)
};
using (new TemplateService(config))
{
string template = #"<html>
<body >
<table >
<tr>
<td'>Description</td>
<td>
#Model.Description
</td>
</tr>
</table>
</body>
</html>";
var model = tm;
return Razor.Parse(template, model);
}
}