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

Categories

0 votes
4.4k 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 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...