Vicheanak Vicheanak - 1 year ago 164
MySQL Question

How to Get Last Id MySQL in Scrapy?

This is the snippet of the code in my pipeline. And I want to get the last inserted ID

result = tx.execute("INSERT INTO articles(title, description, url) VALUES ('" + item['title'] + "', '" + it em['description'] + "', '" + item['url'] + "')"
print('#RESULT', result)

In here, the result printed 1L.

My Purpose: My article as many images, so I want to save them in a different table. By getting the last id of the article, I can use it as a foreign keys to the images table.

How do I do it? Or You have any other practical solutions?

Answer Source

Use tx.lastrowid to get the last row ID inserted

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download