在多个网站上分析电子邮件

2024-04-26 04:50:10 发布

您现在位置:Python中文网/ 问答频道 /正文


我有一个关于在不同的网站上用Scrapy解析电子邮件的问题。
我有这样的蜘蛛:

from scrapy.contrib.spiders import CrawlSpider

from sufio.items import MItem


class MSpider(CrawlSpider):
    name = 'mparser'
    start_urls = [
        'https://horizonsupply.myshopify.com/pages/about-us',
        'https://fnatic-shop.myshopify.com/pages/about-us',
        'https://horizonsupply.myshopify.com/pages/about-us',
        'https://fnatic-shop.myshopify.com/pages/about-us'

    ]
    def parse(self, response):
        item = MItem()
        item['facebook'] = response.xpath('//a[contains(@href, "facebook")]/@href').extract_first()
        item['twitter'] = response.xpath('//a[contains(@href, "twitter")]/@href').extract_first()
#        item['email'] =
        yield item

我需要按照每个链接,并检查,如果有电子邮件。有没有可能用卑鄙的手段来表演呢?你知道吗


Tags: fromhttpsimportcom电子邮件responsepagesitem
1条回答
网友
1楼 · 发布于 2024-04-26 04:50:10

我用这样的方法:

mails = response.xpath('//a[contains(@href, "mailto:")]/@href').extract()
    mails += response.xpath('//*[not(self::script or self::style)]/text()[normalize-space(.)][contains(.,"@")] | '
                            '//a[contains(./@href,"@")]/@href').extract()
    for a in response.xpath('//a[contains(text(),"@")]'):
        ma = ''.join(a.xpath('./text()').extract())
        mails.append(ma)

但在此之后,我使用附加函数来删除重复和无效行。你知道吗

相关问题 更多 >