I have to crawl a lot of sites, is there any way?
my tried code gives an error in the callback-function, but I can't solve it. Is there any way to make my code usable, or to do the callback in a list format?
thank you.
import scrapy
from ..items import AppItem
urls = {
'fun1': 'http://example1.com',
'fun2': 'https://example2.com',
# to add link
# to add link ...
}
item = AppItem()
class Bot(scrapy.Spider):
name = 'app'
def start_requests(self):
for cb in urls:
yield scrapy.Request(url=urls[cb], callback=cb)
def fun1(self, response):
item['title'] = response.css('title')
yield item
def fun2(self, response):
item['title'] = response.css('title')
yield item
error
C:/Python310/python.exe c:/zCode/News/newsScraper/startApp.py
2021-11-26 03:09:06 [scrapy.core.engine] ERROR: Error while obtaining start requests
Traceback (most recent call last):
File "C:\Python310\lib\site-packages\scrapy\core\engine.py", line 129, in _next_request
request = next(slot.start_requests)
File "c:\zCode\News\newsScraper\newsScraper\spiders\app.py", line 18, in start_requests
yield scrapy.Request(url=urls[cb], callback=cb)
File "C:\Python310\lib\site-packages\scrapy\http\request\__init__.py", line 32, in __init__
raise TypeError(f'callback must be a callable, got {type(callback).__name__}')
TypeError: callback must be a callable, got str
: [<Selector xpath='descendant-or-self::title' data='<title>Daum</title>'>]