Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

High memory usage with github page as sample #41

Open
entrptaher opened this issue May 1, 2023 · 10 comments
Open

High memory usage with github page as sample #41

entrptaher opened this issue May 1, 2023 · 10 comments
Assignees
Labels
invalid This doesn't seem right

Comments

@entrptaher
Copy link

image

import requests
from mlscraper.html import Page
from mlscraper.samples import Sample, TrainingSet
from mlscraper.training import train_scraper

# fetch the page to train
einstein_url = 'https://github.com/lorey/mlscraper/issues/38'
resp = requests.get(einstein_url)
assert resp.status_code == 200

# create a sample for Albert Einstein
# please add at least two samples in practice to get meaningful rules!
training_set = TrainingSet()
page = Page(resp.content)
sample = Sample(page, {'title': 'Scraper not found error'})
training_set.add_sample(sample)

# train the scraper with the created training set
scraper = train_scraper(training_set)

# scrape another page
resp = requests.get('https://github.com/lorey/mlscraper/issues/27')
result = scraper.get(Page(resp.content))
print(result)
@lorey
Copy link
Owner

lorey commented May 1, 2023

Thanks for reporting.

General tip: Add more than one sample to see if it persists. Using only one sample cannot yield statistically sound heuristics. Will add a warning. It even says so in the comment you coped!

@lorey
Copy link
Owner

lorey commented May 1, 2023

It's not a memory leak, I assume, it's just using a lot of memory. Usually potential CSS rules get reduced by applying them to every sample. If you add only one, that does not work.

@lorey lorey changed the title Memory Leak with github page as sample High memory usage with github page as sample May 1, 2023
@lorey lorey self-assigned this May 1, 2023
@lorey lorey added bug Something isn't working and removed bug Something isn't working labels May 1, 2023
@lorey
Copy link
Owner

lorey commented May 1, 2023

Same code produces the following result for me withing seconds:

<DictScraper self.scraper_per_key={'title': <ValueScraper self.selector=<CssRuleSelector self.css_rule='bdi'>, self.extractor=<TextValueExtractor>>}>
{'title': 'Improve version pinning'}

Please add dependencies (pip freeze, etc.) and further information to reproduce, so far I'm unable to understand your issue and it works for me with the latest version from the develop branch.

Even the readme clearly states:

If you want to check the new release, use pip install --pre mlscraper to test the release candidate. You can also install the latest (unstable) development version of mlscraper via pip install git+https://github.com/lorey/mlscraper#egg=mlscraper, e.g. to check new features or to see if a bug has been fixed already.

@lorey lorey closed this as completed May 1, 2023
@lorey lorey added the invalid This doesn't seem right label May 1, 2023
@entrptaher
Copy link
Author

If I run this on google colab, I don't get high memory usage but I get 'is not in list' error. However this still causes high memory locally with python 3.10 and mlscraper (both pre and develop versions).

image

Link: https://colab.research.google.com/drive/1frHuWVaAq-86FhhwCSyYlel-qBxaPDIs?usp=sharing

Both python Version 3.9 and 3.10 tested on google colab and locally on ubuntu 22.04

requirements.txt

beautifulsoup4==4.12.2
certifi==2022.12.7
charset-normalizer==3.1.0
idna==3.4
lxml==4.9.2
mlscraper==1.0.0rc3
more-itertools==9.1.0
requests==2.29.0
soupsieve==2.4.1
urllib3==1.26.15

Not sure what is going on. You seem to get a good result while I cannot, using the same code.

@lorey
Copy link
Owner

lorey commented May 2, 2023

Why don't you add a second example?

@lorey
Copy link
Owner

lorey commented May 2, 2023

W was now able to reproduce, will look into this if I find the time.

Seems like it does not stop generating CSS selectors although the tag is unique already.

@lorey lorey reopened this May 2, 2023
@siavashcsr
Copy link

Any news on this issue? I run into the same problem with another website

@drjgouveia
Copy link

I'm running into the same problem :(

@callumb123
Copy link

Has anyone managed to work around this yet? Tried a number of different sites with 5+ samples for each but always running out of memory.

@ErikZhang-9762
Copy link

Same problem,i have 32g memory but always running out of memory :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

6 participants