Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何检查网站是否已更改其WebElement_Python 3.x_Beautifulsoup_Request - Fatal编程技术网

Python 3.x 如何检查网站是否已更改其WebElement

Python 3.x 如何检查网站是否已更改其WebElement,python-3.x,beautifulsoup,request,Python 3.x,Beautifulsoup,Request,我一直在努力,在那里我刮一些水果的数据,以获得一个打印,以了解是否有一个网页上的变化等价格已被降低或更改标题名称等 import time import requests from bs4 import BeautifulSoup def scrape(): headers = { 'pragma': 'no-cache', 'cache-control': 'no-cache', 'sec-ch-ua': '" Not A

我一直在努力,在那里我刮一些水果的数据,以获得一个打印,以了解是否有一个网页上的变化等价格已被降低或更改标题名称等

import time

import requests
from bs4 import BeautifulSoup


def scrape():
    headers = {
        'pragma': 'no-cache',
        'cache-control': 'no-cache',
        'sec-ch-ua': '" Not A;Brand";v="99", "Chromium";v="90", "Google Chrome";v="90"',
        'sec-ch-ua-mobile': '?0',
        'upgrade-insecure-requests': '1',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.93 Safari/537.36',
        'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
        'sec-fetch-site': 'none',
        'sec-fetch-mode': 'navigate',
        'sec-fetch-user': '?1',
        'sec-fetch-dest': 'document',
        'accept-language': 'sv-SE,sv;q=0.9,en-US;q=0.8,en;q=0.7',
    }

    response = requests.get(
        'https://www.bigbasket.com/pd/40033824/fresho-apple-red-delicious-regular-4-pcs/?nc=feat-prod&t_pg=l1-cat-fruits-vegetables&t_p=cl-temp-1&t_s=feat-prod&t_pos_sec=3&t_pos_item=1&t_ch=desktop',
        headers=headers)
    
    if response.ok:
        soup = BeautifulSoup(response.text, 'lxml')
    
        name = soup.find('h1', attrs={"class": "GrE04"}).text
        price = soup.find(attrs={"data-qa": "productPrice"}).text
        image = soup.find(attrs={"class": "_3oKVV"}).get('src')
    
        return {
            "name": name,
            "price": price,
            "image": image
        }
    else:

        return {
            "name": None,
            "price": None,
            "image": None
        }

def main():
    first_request = scrape()

    while True:
        new_request = scrape()

        if first_request["price"] != new_request["price"]:
            print("New change have happend in the price!")
            time.sleep(5)
            first_request = new_request

        else:
            print("Lets check in 5 minutes if there has been changes")
            first_request = new_request
            time.sleep(300)


if __name__ == '__main__':
    main()
然而,我目前的问题是,我不知道如何在页面更改时通知自己。我们无法将整个网页与以前的请求进行比较,因为在页面底部有一个“类似产品”,它似乎在x数量的请求上发生变化

我如何通知自己是否网页做了一些更改,例如更改了我在代码中编写的标记的webelement标记