Package: pypartpicker
PyPartPickerPyPartPicker is a package that allows you to obtain information from PCPartPicker quickly and easily, with data being returned via objects with numerous attributes.Features:Obtain Part objects, estimated wattage and total cost from PCPartPicker lists.Obtain name, product URL, price, product type, image and more from Part objects.Obtain everything previously mentioned + specs, reviews and in depth pricing information from PCPartPicker product links.Async ready: all scraping methods have an asynchronous versionInstallationInstallation via pip:>>> pip install pypartpickerOr clone the repo directly:>>> git clone https://github.com/thefakequake/pypartpicker.gitExample programsHere is a program that searches for i7's, prints every result, then gets the first result and prints its specs:frompypartpickerimportScraper# creates the scraper objectpcpp=Scraper()# returns a list of Part objects we can iterate throughparts=pcpp.part_search("i7")# iterates through every part objectforpartinparts:# prints the name of the partprint(part.name)# gets the first product and fetches its URLfirst_product_url=parts[0].url# gets the Product object for the itemproduct=pcpp.fetch_product(first_product_url)# prints the product's specs using the specs attributeprint(product.specs)Here is another program that finds i3s that are cheaper than or equal to £110, prints their specs and then prints the first review:frompypartpickerimportScraperfromtimeimportsleep# returns a list of Part objects we can iterate through# the region is set to "uk" so that we get prices in GBPpcpp=Scraper()parts=pcpp.part_search("i3",region="uk")# iterates through the partsforpartinparts:# checks if the price is lower than 110iffloat(part.price.strip("£"))<=110:print(f"I found a valid product:{part.name}")print(f"Here is the link:{part.url}")# gets the product object for the partsproduct=pcpp.fetch_product(part.url)print(product.specs)# makes sure the product has reviewsifproduct.reviews!=None:# gets the first reviewreview=product.reviews[0]print(f"Posted by{review.author}:{review.content}")print(f"They rated this product{review.rating}/5.")else:print("There are no reviews on this product!")# slows down the program so as not to spam PCPartPicker and potentially get IP bannedsleep(3)Creating the Scraper objectScraper(headers={...}, response_retriever=...)Parametersheaders(dict) - The browser headers for the requests in a dict.Note: There are headers set by default. I only recommend changing them if you are encountering scraping errors.response_retriever(Callable) - A function accepting arguments (url, **kwargs) that is called to retrieve the response from PCPartPickerNote: A default retriever is configured that calls pcpartpicker.com directly. I only recommend changing this if you need to configure how the request is made (e.g. via a proxy)Scraper MethodsScraper.part_search(search_term, limit=20, region=None)Returns Part objects using PCPartPicker's search function.Parameterssearch_term(str) - The term you want to search for.Example:"i5"limit(Optional[int]) - The amount of results that you want to be returned.Example:limit=5region(Optional[str]) - The country code of which you want the pricing for the Part objects to be in.Example:region="uk"ReturnsA list of Part objects corresponding to the results on PCPartPicker.Scraper.fetch_product(product_url)Returns a Product object from a PCPartPicker product URL.Parametersproduct_url(str) - The product URL for the product you want to search for.Example:"https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box"ReturnsA Product object for the part.Scraper.fetch_list(list_url)Returns a PCPPLIst object from a PCPartPicker list URL.Parameterslist_url(str) - The URL for the parts list.Example:"https://pcpartpicker.com/list/Tzx22V"ReturnsA PCPPList object for the list.Other methodsget_list_links(string)Returns a list of PCPartPicker list links from the given string.Parametersstring(str) - The string containing the parts list URL.Example:"this function can extract the link from this string https://pcpartpicker.com/list/Tzx22V"ReturnsA list of URLs.get_product_links(string)Returns a list of PCPartPicker product links from the given string.Parametersstring(str) - The string containing the product URL.Example:"this function can extract the link from this string https://pcpartpicker.com/product/9nm323/amd-ryzen-5-3600-36-thz-6-core-processor-100-100000031box"ReturnsA list of URLs.Async MethodsSame syntax as sync functions, but add aio_ to the beginning of the method name and add await before the function call.For example:pcpp=Scraper()results=pcpp.part_search("i5")becomespcpp=Scraper()results=awaitpcpp.aio_part_search("i5")Remember: you can only call async functions within other async functions. If you are not writing async code, do not use these methods. Use the sync methods, which don't have aio_ before their name.Only the blocking functions (the ones that involve active scraping) have async equivalents.ObjectsPartAttributesname- The name of the parturl- The product URL for the parttype- The type of the part (e.g. CPU, Motherboard, Memory)price- The cheapest price for the partimage- The image link for the partProductAttributesAll attributes from Partspecs- The specs for the product, arranged in a dictionary with the values being listsprice_list- A list of Price objects containing all the merchants, prices and stock valuesrating- The total user ratings and average score for the productreviews- A list of Review objects for the productcompatible_parts- A list of tuples containing the compatible parts links for the productPriceAttributesvalue- The final price valuebase_value- The price value before shipping and other discountsseller- The name of the company selling the partseller_icon- The icon URL for the company selling the parturl- The URL which links to the seller's product listingin_stock- A boolean of whether the product is in stockReviewAttributesauthor- The name of the person who posted the reviewauthor_url- The URL which points to the author's profileauthor_icon- The icon URL of the person who posted the reviewpoints- The amount of upvotes on the reviewcreated_at- How long ago the review was sentrating- The star rating out of 5 of the product that the review givescontent- The text content of the reviewPCPPListAttributesparts- List of Part objects corresponding to every part in the listwattage- The estimated wattage for the parts in the listtotal- The total price of the PCPartPicker listurl- The URL of the PCPartPicker listcompatibility- A list containing the compatibility notes for the parts list