문제

I'm looking for a library that has a similar API and usage as jQuery or Cheerio.

My use case is: parsing an HTML file for any script or link tags containing javascript/css file references.

도움이 되었습니까?

해결책

Python equivalent for jQuery is pyQuery. Under that link you can find usage examples. You can also visit PyQuery on GitHub.

다른 팁

Although pyQuery is the jQuery equivalent, judging by your use case I think maybe something like BeautifulSoup could be better suited for what you're looking to do.

The following is taken from the official Beautiful Soup website:

Beautiful Soup is a Python library designed for quick turnaround projects like screen-scraping. Three features make it powerful:

  1. Beautiful Soup provides a few simple methods and Pythonic idioms for navigating, searching, and modifying a parse tree: a toolkit for dissecting a document and extracting what you need. It doesn't take much code to write an application

  2. Beautiful Soup automatically converts incoming documents to Unicode and outgoing documents to UTF-8. You don't have to think about encodings, unless the document doesn't specify an encoding and Beautiful Soup can't autodetect one. Then you just have to specify the original encoding.

  3. Beautiful Soup sits on top of popular Python parsers like lxml and html5lib, allowing you to try out different parsing strategies or trade speed for flexibility.

Beautiful Soup parses anything you give it, and does the tree traversal stuff for you. You can tell it "Find all the links", or "Find all the links of class externalLink", or "Find all the links whose urls match "foo.com", or "Find the table heading that's got bold text, then give me that text."

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top