#๐ scrapping photos off the internet
54 messages ยท Page 1 of 1 (latest)
@jade acorn
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
ping or dm to answer
5. Do not provide or request help on projects that may violate terms of service, or that may be deemed inappropriate, malicious, or illegal.
If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/
After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.
You might want to do some error checking before trying to download the image. Make sure the URL is actually an image, perhaps you're saving the response of a 404 page or something to the file.
Also, you might want to keep the original file extensions lol
- the url is the url of the image itself and yes it works 100% completly fine
so good actually that if u look in the vid when i open the files through the terminal
everything is fine and i can c the pics
but idk why is it funky when i open file exploarer
i can't see the images all i c is that stuff u saw in the vid
- it is the same extentions
coz i take it from the orriginal link
and for my code
import requests
from bs4 import BeautifulSoup
response = requests.get("https://www.monsterhouseplans.com/house-plans/modern-farmhouse-style/2373-sq-ft-home-1-story-4-bedroom-2-bath-house-plans-plan50-381/")
soup = BeautifulSoup(response.content, "html.parser")
tag = soup.find(name="div", class_ = "housePlanDetailTitleLeftSec").find("strong").text[1:]
specs = soup.find(name="div", class_ = "housePlanKeySpecs").find_all(name="li")
list_specs = []
for e in specs:
list_specs.append(e.find("span").text.lstrip().rstrip().split()[0])
plans = soup.find_all(name="div", class_="housePlanFieldSetHolder")
names = []
sorces = []
for plan in plans:
images = plan.find_all("img")
for image in images:
names.append(image.get("alt"))
sorces.append(image.get("data-src"))
for e in list(range(len(names))):
response = requests.get(sorces[e]).content
filename = f"{names[e]}.{sorces[e].split(".")[-1]}"
print(filename)
with open(filename, "wb") as fp:
fp.write(response)
here u guys go
@tropic sluice
@fallen sorrel
So... what's wrong?
It's creating a blank text file?
Hmm, I just ran the code and it seems to be working
these 5 images are downloaded correctly
laminar what OS are you using?
And they're on windows. I'm thinking the : character might be messing with things because that's not a valid character for filenames for windows
Since your files seem to appear fine in vs code but theirs are not. Not sure what's going on with selecting them from the console though
@jade acorn try cleaning the filenames from special characters that windows doesn't allow
If it solved it use !solved to close the thread
!solved
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.