docs: general correction across all the pages
Automated. I don't know how I missed all of that!
This commit is contained in:
@@ -21,7 +21,7 @@ You will notice that some shortcuts in BeautifulSoup are missing in Scrapling, w
|
||||
| Using CSS selectors to find the first matching element | `elements = soup.select_one('div.example')` | `elements = page.css('div.example').first` |
|
||||
| Using CSS selectors to find all matching element | `elements = soup.select('div.example')` | `elements = page.css('div.example')` |
|
||||
| Get a prettified version of the page/element source | `prettified = soup.prettify()` | `prettified = page.prettify()` |
|
||||
| Get a Non-pretty version of the page/element source | `source = str(soup)` | `source = page.body` |
|
||||
| Get a Non-pretty version of the page/element source | `source = str(soup)` | `source = page.html_content` |
|
||||
| Get tag name of an element | `name = element.name` | `name = element.tag` |
|
||||
| Extracting text content of an element | `string = element.string` | `string = element.text` |
|
||||
| Extracting all the text in a document or beneath a tag | `text = soup.get_text(strip=True)` | `text = page.get_all_text(strip=True)` |
|
||||
@@ -36,14 +36,16 @@ You will notice that some shortcuts in BeautifulSoup are missing in Scrapling, w
|
||||
| Searching for elements in the siblings of an element | `target_sibling = element.find_next_siblings("a")`<br/>`target_sibling = element.find_previous_siblings("a")` | `target_sibling = element.siblings.filter(lambda s: s.tag == 'a')` |
|
||||
| Searching for an element in the next elements of an element | `target_parent = element.find_next("a")` | `target_parent = element.below_elements.search(lambda p: p.tag == 'a')` |
|
||||
| Searching for elements in the next elements of an element | `target_parent = element.find_all_next("a")` | `target_parent = element.below_elements.filter(lambda p: p.tag == 'a')` |
|
||||
| Searching for an element in the previous elements of an element | `target_parent = element.find_previous("a")` | `target_parent = element.path.search(lambda p: p.tag == 'a')` |
|
||||
| Searching for elements in the previous elements of an element | `target_parent = element.find_all_previous("a")` | `target_parent = element.path.filter(lambda p: p.tag == 'a')` |
|
||||
| Searching for an element in the ancestors of an element | `target_parent = element.find_previous("a")` ¹ | `target_parent = element.path.search(lambda p: p.tag == 'a')` |
|
||||
| Searching for elements in the ancestors of an element | `target_parent = element.find_all_previous("a")` ¹ | `target_parent = element.path.filter(lambda p: p.tag == 'a')` |
|
||||
| Get previous sibling of an element | `prev_element = element.previous_sibling` | `prev_element = element.previous` |
|
||||
| Navigating to children | `children = list(element.children)` | `children = element.children` |
|
||||
| Get all descendants of an element | `children = list(element.descendants)` | `children = element.below_elements` |
|
||||
| Filtering a group of elements that satisfies a condition | `group = soup.find('p', 'story').css.filter('a')` | `group = page.find_all('p', 'story').filter(lambda p: p.tag == 'a')` |
|
||||
|
||||
|
||||
¹ **Note:** BS4's `find_previous`/`find_all_previous` searches all preceding elements in document order, while Scrapling's `path` only returns ancestors (the parent chain). These are not exact equivalents, but ancestor search covers the most common use case.
|
||||
|
||||
**One key point to remember**: BeautifulSoup offers features for modifying and manipulating the page after it has been parsed. Scrapling focuses more on scraping the page faster for you, and then you can do what you want with the extracted information. So, two different tools can be used in Web Scraping, but one of them specializes in Web Scraping :)
|
||||
|
||||
### Putting It All Together
|
||||
|
||||
Reference in New Issue
Block a user