同じスパイダーを一度再起動すると、処理するURLの次のリストを取得できます。私のデータベースは大きすぎるので、一度にすべてのウェブサイトをパスすることはできません。だから私は100のウェブサイトを処理するためにループで実行する必要がありますスパイダーを処理し、再び100のWebサイトなどをフェッチする必要があります。 100のウェブサイトを処理し終わったら、スパイダーに電話する方法はありますか?私が治療に慣れていないので、問題のために私を助けてください。または指定された時間間隔の後にスパイダーを実行するようにスケジューリングするオプションはありますか?スクラピースパイダーの再帰呼び出し
現在のコードでは、ドメインからURLを取得してデータベースに格納できます。しかし、私はいつもクモを実行する必要があります。それを一度実行する方法はありますか?それは処理するWebサイトがなくなるまで継続して実行されます。助けてください。
class MyItem(Item):
url = Field()
class MySpider(CrawlSpider):
con = MySQLdb.connect(host="localhost", user="user",
passwd="pwd", db="db")
cur = con.cursor(MySQLdb.cursors.DictCursor)
cur.execute("select website from table limit 100")
name = "first"
urls = []
domains = []
allowed_domains = []
start_urls = []
row = cur.fetchone()
while row is not None:
p = "%s" % (row["website"])
domains.append(p)
start_urls = "http://www.% s" % p
urls.append(start_urls)
row = cur.fetchone()
allowed_domains = domains
start_urls = urls
cur.close()
con.close()
print(start_urls)
rules = (Rule(SgmlLinkExtractor(), callback='parse_url', follow=True),)
connection = MySQLdb.connect(host="localhost", user="user",
passwd="pwd", db="db")
cursor = connection.cursor(MySQLdb.cursors.DictCursor)
def parse_url(self, response):
item = MyItem()
item['url'] = response.url
topDomain = tldextract.extract(response.url)
tld = topDomain.domain + '.' + topDomain.suffix
add_url = "INSERT INTO crawl_db (url,tld,time) VALUES (%s,%s,%s)"
add_url_data = (item['url'], tld, strftime("%Y-%m-%d %H:%M:%S", gmtime()))
self.cursor.execute(add_url, add_url_data)
self.connection.commit()
ありがとうございます。