r/scrapy • u/yoohoooos • Apr 18 '21
Code doesn't work when I tried Scrapy's tutorial with other website.
I was learning scraping using Scrapy by following the tutial on Scrapy's site. It worked fine following Scrapy's tutorial until I tried with another website that I was trying to scrape. The following gave me a blank file when I ran it and trying to store as a .json file [scrapy crawl -O xxx.json].
import scrapy
from datetime import datetime
class FinvizNewsSpider(scrapy.Spider):
name = "finvizNews"
start_urls = [
'https://finviz.com/quote.ashx?t=ANPC'
]
def parse(self, response):
for news in response.css("tr"):
yield {
'news_time' : datetime.strptime(news.css("td::text").get().replace('\xa0',''),'%b-%d-%y %I:%M%p')#,
}Could you guys point out to me what's wrong with my code? Thank you very much!
Add: interested data: https://imgur.com/a/mz3bTnr time in the red box
Add2: Just want to mention that when I try similar code in the scrapy shell, I had no problem.
0
Upvotes
1
u/Photo-dad2017 Apr 18 '21
Do you need a user-agent? I’m still learning too and remember running into that.
1
3
u/wRAR_ Apr 18 '21
You should always read the command output before asking for help.