Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.3k views
in Technique[技术] by (71.8m points)

Update Specific Rows via Scraped Data on Python Postgresql

I am new to Python/Django, so please bear with me! I've read all the other threads but I still don't get it done. I have a django framework blog having a user pages that user can create and follow item prices. My client can be create new item and follow prices and stock status.

client_table:

ID  ITEMNO  PRICE
1   TMEP       
2   TMEP       
3   TMEP       
4   TTVP       
5   TMEP       
6   TTVP       

Thos rows goes on 1000+ now and as you can see a lot of my client following same items. I have an also a little bs4 engine that scrape prices on api and save in another table.

scraped_data_table :

ID  ITEMNO  PRICE 
1   TMEP    78,5€   
2   TTVP    112,00€   

mybs4:

class Command(BaseCommand):
    def handle(self,  *args, **options):)
        html = urlopen('')
        soup = BeautifulSoup(html, 'html.parser')
        site=json.loads(soup.text)

        for i in range(len(site)):
            price = site[i]['priceeu']

            try:
                Job.objects.create(
                    price=price,

                )
                print('%s added' % (price,))
            except Exception as e: print(e)
        self.stdout.write( 'Well Done' )

I'd try to change try method like Job.objects.update and write on client_table but didnt figure out.

client_table after scraped prices.

ID  ITEMNO  PRICE
1   TMEP    78,5   
2   TMEP    78,5   
3   TMEP    78,5   
4   TTVP    78,5   
5   TMEP    78,5   
6   TTVP    78,5   

I have to seek help here as a last resort. I really appreciate if someone could help me out. Thank you in advance.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...