Regex Scraper
Project description
ReScrap
Presentation
Library for scraping:
- .txt file
- pdf file
- web pages
Modules
ReScrap
ReScrapFile
PDF and Text file scraping
ReScrapWeb
Web scraping from an url or html string.
Example
from rescrap.rescrapweb import ReScrapWeb
url = "https://example.com/"
rsw = ReScrapWeb(url=url)
rsw.find('h1').text
>>> 'Example Domain'
VS BeautifulSoup
keywords = "covid"
date_now = datetime.now().strftime("%d/%m/%Y")
url = f"https://www.lemonde.fr/recherche/?search_keywords={'+'.join(keywords.split(' '))}&start_at=19/12/1944&end_at={date_now}&search_sort=date_desc"
def test_bs4(url):
r = requests.get(url)
web_content = BeautifulSoup(r.text, "lxml")
news_liste = web_content.findAll("section", class_="teaser teaser--inline-picture")
news_title = []
for news_item in news_liste:
if news_item.find("span", class_="meta__date"):
links = news_item.find("a", href=True)["href"]
news = news_item.find("h3", class_="teaser__title").text
date = (
news_item.find("span", class_="meta__date")
.text.split(",")[0]
.split(" - ")[0]
.replace("Publié ", "")
.capitalize()
)
news_title.append((news, links, date))
return news_title
def test_rescrap(url):
rsw = ReScrapWeb(url=url)
news_liste = rsw.find_all("section", class_="teaser--inline-picture")
news_title = []
for news_item in news_liste:
if news_item.find("span", class_="meta__date"):
links = news_item.find_value("a", "href")
news = news_item.find("h3", class_="teaser__title").text
date = (
news_item.find("span", class_="meta__date")
.text.split(",")[0]
.split(" - ")[0]
.replace("Publié ", "")
.capitalize()
)
news_title.append((news, links, date))
return news_title
Benchmark :
%%timeit
test_bs4(url)
>>> 824 ms ± 40.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%%timeit
test_rescrap(url)
>>> 576 ms ± 21.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
%%time
test_bs4(url)
>>> CPU times: user 565 ms, sys: 23.6 ms, total: 588 ms
Wall time: 811 ms
%%time
test_rescrap(url)
>>> CPU times: user 386 ms, sys: 79 µs, total: 386 ms
Wall time: 582 ms
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
rescrap-0.1.2.tar.gz
(5.2 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rescrap-0.1.2.tar.gz.
File metadata
- Download URL: rescrap-0.1.2.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.12 Linux/5.10.0-10-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1104d5895eac586639f40c676c036a67dc3e3d589cb09f96a24219d95d4db4c7
|
|
| MD5 |
27206380392d29b428dc8244272ca0a1
|
|
| BLAKE2b-256 |
b52a627a94a90914564e43e2c423ddac275b02331bf4511dd22f2bdd75b20511
|
File details
Details for the file rescrap-0.1.2-py3-none-any.whl.
File metadata
- Download URL: rescrap-0.1.2-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.13 CPython/3.9.12 Linux/5.10.0-10-amd64
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
226c308b750fb340a8f5a0b12cca93b4c6764a8fd505d20901720853f25ba9bd
|
|
| MD5 |
f8e943b798586eb31cb5f6671074ee6e
|
|
| BLAKE2b-256 |
c40ec02a8cc1081f3204a162d147f290780ae4962ed40a098f42c7d61cadea56
|