HTML code does not display the image in email - python

I have the below HTML code that I am passing through a python script to send out an email. I am able to get the email however I am trying to have an image added to the body of the email but I see that the image does not get added to the email. I have the image saved to a variable called image and I am trying to call this variable. It just shows a greyed out area in the position where the image needs to be shown.
image = 'file.png'
f"""
<html>
<body style="background-color:#fafafa;">
<div class="row">
<div style="float:left;width: 20%;padding: 10px;">
</div>
div align="center" style="float:left;width: 60%;padding: 10px;">
<img src="cid:image" align="middle" width="253" height="68">
<br>
<h1 style="color:#9FA6B5;font-family:sans-serif;font-weight:200;text-align: center;">{name}</h1>
</div>
<div style="float:left;width: 20%;padding: 10px;">
</div>
</div>
</body>
</html>"""

You given the local path of the image, which can not be send to your email, you have to give path of the image from server image folder to show your image.

You have to upload your images to a server image then include the path into your src tag.
Here is a server i use to upload images for HTML email templates.

Related

Image not showing div class

When I insert an image on my html file it not showing on the page
index.html
<!-- start banner section -->
<section class="xs-banner-sec owl-carousel banner-slider">
<div class="banner-slider-item banner-item1" style="background-image: url(assets/images/banner-slider/banner_slider_1.jpg);">
<div class="slider-table">
<div class="slider-table-cell">
<div class="container">
<div class="row align-items-center">
<div class="col-lg-10 offset-lg-1">
<div class="banner-content text-center">
<h2>Best Gardening Service</h2>
<p>Wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring
whole
heart.
</p>
and this is my folder
Does the div have a width or height? Divs will not take up space by default even with a background image as it isnt concidered content. Try giving it a height of 200px and a width of 200px just to test.
You should write background instead of background -image. cause it was not working for me until I changed it to background
<div class="banner-slider-item banner-item1" style="background: url(assets/images/banner-slider/banner_slider_1.jpg);">

Scrapy Scrape element within unknown number of <div>

I am trying to scrape a list of website on Shopee. Some example include dudesgadget and 2ubest. Each of these shopee shop have different design and way of constructing their web element and different domain as well. They looks like stand alone website but they are actually not.
So the main problem here is I am trying to scrape the product details. I will summarize some different structure:
2ubest
<html>
<body>
<div id="shopify-section-announcement-bar" id="shopify-section-announcement-bar">
<main class="wrapper main-content" role="main">
<div class="grid">
<div class="grid__item">
<div id="shopify-section-product-template" class="shopify-section">
<script id="ProductJson-product-template" type="application/json">
//Things I am looking for
</script>
</div>
</div>
</div>
</main>
</div>
</body>
</html>
littleplayland
<html>
<body id="adjustable-ergonomic-laptop-stand" class="template-product">
<script>
//Things I am looking for
</script>
</body>
</html>
And few other, and I had discover a pattern between them.
The thing that I am looking for will for sure in <body>
The thing that I am looking for is within a <script>
The only thing that I not sure is the distance from <body> to <script>
My solution is:
def parse(self, response):
body = response.xpath("//body")
for script in body.xpath("//script/text()").extract():
#Manipulate the script with js2xml here
I am able to extract the littleplayland, dailysteals and many others which has very less distance from the <body> to <script>, but does not works for the 2ubest which has a lot of other html element in between to the thing I am looking for. Can I know are there solution that I can ignore all the html element in between and only look for the <script> tag?
I need a single solution that are generic and can work across all Shopee website if possible since all of them have the characteristic that I had mention above.
Which mean that the solution should not filter using <div> because every different website have different numbers of <div>
This is how to get the scripts in your HTML using Scrapy:
scriptTagSelector = scrapy.Selector(text=text, type="html")
theScripts = scriptTagSelector.xpath("//script/text()").extract()
for script in theScripts:
#Manipulate the script with js2xml here
print("------->A SCRIPT STARTS HERE<--------")
print(script)
print("------->A SCRIPT ENDS HERE<--------")
Here is an example with the HTML in your question (I added an extra script :) ):
import scrapy
text="""<html>
<body>
<div id="shopify-section-announcement-bar" id="shopify-section-announcement-bar">
<main class="wrapper main-content" role="main">
<div class="grid">
<div class="grid__item">
<div id="shopify-section-product-template" class="shopify-section">
<script id="ProductJson-product-template" type="application/json">
//Things I am looking for
</script>
</div>
<script id="script 2">I am another script</script>
</div>
</div>
</main>
</div>
</body>
</html>"""
scriptTagSelector = scrapy.Selector(text=text, type="html")
theScripts = scriptTagSelector.xpath("//script/text()").extract()
for script in theScripts:
#Manipulate the script with js2xml here
print("------->A SCRIPT STARTS HERE<--------")
print(script)
print("------->A SCRIPT ENDS HERE<--------")
Try this:
//body//script/text()

How do I add a background image for a div container?

So I am having a bit of trouble inserting an image inside of a div container. At the top of my page I have a fixed navbar and, underneath the navbar, I have a jumbotron div with a div container with the name of the company as well as the tagline. Instead of there being a bg color for the div jumbotron/div container, I would like there to be an image instead that relates to the services and products that are being provided.
I am using Python Django to create the site and thus am using Jinja to implement static files such as images. Below is the code that I've used that does not work. I would like to be able to implement the image using this same Jinja method of static files rather than url(path to image here)... help?
<div>
<div class="jumbotron">
<div class="container" style="background-image:{% static 'company/img/familypic.jpg' %}">
<center><h2>Whatever Text Here</h2></center>
<center><h4>Whatever Tagline Here</h4></center>
</div>
</div>
</div>
It has to be url('{% static 'company/img/familypic.jpg' %}') for the background-image to show up.
Use
<div class="" style="background-image: url({{ static('company/img/familypic.jpg') }});">

How to download all images under one specific node in Scrapy?

I am using Scrapy, I want to download all images under one node, for example, here is the web page:
<!-- language: lang-xml -->
<div class="A">
<div class="A1">
<div class="A2">
<img original="a1.png"></img>
</div>
</div>
<div class="A3">
<img original="a2.png"></img>
</div>
</div>
<div class="B">
<div class="B1">
<div class="B2">
<img original="b1.png"></img>
</div>
</div>
<div class="B3">
<img original="b2.png"></img>
</div>
</div>
I want to download all images (I need to find the original urls for these images) under class="A" but not class="B", and under class="A" we have a1.png and a2.png, they are at different levels (the number of level is uncertain).
Is there any way to target one attribute under one specific node using XPATH (something like //div[#class="A"]/**/img ) ?
or is there any solution in Scrapy?
Using the following XPath to select all img nodes that are descendants of a div node with class A:
//div[#class="A"]//img
Demo
The // matches descendants, as opposed to /, which matches direct children.

How to display image in Python-cgi

I am beginner and i dont know where i am doing mistake. i have seen these stack posts Return an image to the browser in python, cgi-bin , Return Image from python CGI using javascript and How to loading/show a picture in a Python CGI page but got no help.
Here is the code:
#!C:\Python27\python
text = """Content-type: text/html\n
<TITLE> CGI 101 </TITLE>
<H1>A SECOND CGI SCRIPT </H1>
<HR>
<P> HELLO,CGI WORLD!</P>
<img src="../imag000.jpg" width=101 height=64 border=0 alt="">
<HR>
"""
print (text)
and on browser it appears small box which is not showing image, like this:
Kindly help.
and folder which contains image is cgi. Kindly see picture:
Here is the best Solution:
<img src="http://localhost/imag000.jpg" width=101 height=64 border=0 alt="">
The HTML claims that the image is in the parent directory, but the server has it in the same directory. Either modify the HTML to match the current image location, or move the image to where the browser is requesting it from.

Categories