Wie filtert man Websites nach ihren Schlüsselwörtern in Metadaten?Python

Python-Programme
Anonymous
 Wie filtert man Websites nach ihren Schlüsselwörtern in Metadaten?

Post by Anonymous »

Ich habe einen Scraper geschrieben, der nur Websites mit Schlüsselwörtern scannen soll, die mit den angegebenen übereinstimmen. Dies ist der Code:

Code: Select all

class MySpider(CrawlSpider):
name = 'smm'
allowed_domains = []
start_urls = ['http://en.wikipedia.org/wiki/Social_media']
rules = (
Rule(SgmlLinkExtractor(deny=('statcounter.com/','wikipedia','play.google','books.google.com','github.com','amazon','bit.ly','wikimedia','mediawiki','creativecommons.org')), callback="parse_items", follow= True),
)
def parse_items(self, response):
items = []
#Define keywords present in metadata to scrape the webpage
keywords = ['social media','social business','social networking','social marketing','online marketing','social selling',
'social customer experience management','social cxm','social cem','social crm','google analytics','seo','sem',
'digital marketing','social media manager','community manager']
#Extract webpage keywords
metakeywords = response.xpath('//meta[@name="keywords"]').extract()
#Discard empty keywords
if metakeywords != []:
#Compare keywords and extract if one of the defined keyboards is present in the metadata
if (keywords in metaKW for metaKW in metakeywords):
for link in response.xpath("//a"):
item = SocialMediaItem()
item['SourceTitle'] = link.xpath('/html/head/title').extract()
item['TargetTitle'] = link.xpath('text()').extract()
item['link'] = link.xpath('@href').extract()
item['webKW'] = metakeywords
outbound = str(link.xpath('@href').extract())
if 'http' in outbound:
items.append(item)
return items
Allerdings glaube ich, dass mir etwas fehlt, da es auch Websites ohne die Gicen-Schlüsselwörter durchsucht. Können Sie helfen, dieses Problem zu lösen?
Danke!
Dani

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post