-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path10_real_world.py
More file actions
36 lines (26 loc) · 855 Bytes
/
10_real_world.py
File metadata and controls
36 lines (26 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
"""Real-world scraping example."""
import easyscrape as es
def scrape_article(url: str) -> dict:
"""Extract article information."""
result = es.scrape(url)
return {
"url": url,
"title": result.title(),
"content": result.main_text()[:500],
"links": len(result.safe_links()),
"images": len(result.safe_images()),
"meta": result.meta(),
}
def main():
url = "https://httpbin.org/html"
print("=== Scraping Article ===")
article = scrape_article(url)
print(f"Title: {article['title']}")
print(f"Content: {article['content'][:200]}...")
print(f"Links: {article['links']}")
print(f"Images: {article['images']}")
if article["meta"]:
print(f"Meta tags: {list(article['meta'].keys())[:5]}")
if __name__ == "__main__":
main()