问题
I am trying to use Scrapy to extract data from page. But I get an empty output. What is the problem?
spider:
class Ratemds(scrapy.Spider):
name = 'ratemds'
allowed_domains = ['ratemds.com']
custom_settings = {
'USER_AGENT': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36 OPR/60.0.3255.50747 OPRGX/60.0.3255.50747',
}
def start_requests(self):
yield scrapy.Request('https://www.ratemds.com/doctor-ratings/dr-aaron-morrow-md-greensboro-nc-us' , callback=self.profile)
def profile(self, response):
item = {
'url': response.request.url,
'Image': response.css('.doctor-profile-image::attr(src)').get(),
'First_and_Last_Name': response.css('h1::text').get()
}
yield item
output:
{'url': 'https://www.ratemds.com/doctor-ratings/dr-aaron-morrow-md-greensboro-nc-us', 'Image': None, 'First_and_Last_Name': None}
来源:https://stackoverflow.com/questions/62601706/scrapy-output-empty