M
M
majorlazer14882020-06-03 06:33:21
Python
majorlazer1488, 2020-06-03 06:33:21

How to specify ::before when writing to html file?

I have photo scraping code

import scrapy

class RedditSpider(scrapy.Spider):
  name = 'avt'
  start_urls = ['https://www.avito.ru/sankt-peterburg/avtomobili/mazda_6_2008_1947668359']

  def parse(self, response):
    links = response.xpath('//img[contains(@src, "img.avito")]/@src')
    html = ""

    for link in links:
      url = link.get()

      if any(extension in url for extension in ['.png', 'jpg', 'gif']):
        html += """<a href="{url}"
        target="_blank">
        <img src="{url}" height="33%"
        width="33%"/>
        <a/>""".format(url=url)

        with open('img.html', 'a') as file:
          file.write(html)

But when opening img.html the images are not displayed.
Here is the element code
<div class="gallery-list-item-link">
  ::before
  <img src="//79.img.avito.st/75x55/8691702679.jpg" alt="Mazda 6, 2008, с пробегом, цена 450 000 руб."> 
</div>
::after

I think that you need to specify the ::before/after pseudo-element somehow, but I have no idea how

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question