wget: don't follow redirects if it points to location X, otherwise do
As @Thor84no said, one solution can parse response. This is mine:
REDIRECTED_TO=`wget --max-redirect 0 $ADDRESS 2>&1 | grep "Location" | sed 's|.*\(http://.*/.*\) .*|\1|'`
if [ "$REDIRECTED_TO" != "$BAD_REDIRECTION" ]; then wget $REDIRECTED_TO; fi
Wget redirects even though robots are off
Interestingly the website example you've provided returns results based on the user-agent
string. With the default user-agent, the server returns a 301 response and asks wget to download only the first page.
You can simply change the user-agent string to make it work. e.g.:--user-agent=mozilla
Wget doesn't download recursively after following a redirect
You need to use --span-hosts
(-H
) with --domains
:
wget --recursive --level=10 --convert-links -H \
--domains=www.btlregion.ru btlregion.ru
--span-hosts
allows wget
to follow links pointing to other domains, and --domains
restricts this to only follow links to the listed domains, to avoid downloading the internet.
The option --domains
will, somewhat contrary to intuition, only work together with -H
. This is mentioned in the docs, but in a way that's hard to understand.
Related Topics
How Does Execve Call Dynamic Linker/Loader (Ld-Linux.So.2)
Differencebetween Ldd and Objdump
Postgresql on Elastic Beanstalk (Amazon Linux 2)
How to Receive the Wrong Ethernet Frames and Disable the Crc/Fcs Calcul
How Do Locales Work in Linux/Posix and What Transformations Are Applied
How to Respond to Prompts in a Linux Bash Script Automatically
How to Know the Creation Time of a File in Ubuntu
Replace First Few Lines with First Few Lines from Other File
Where Are Ioctl Parameters (Such as 0X1268/Blksszget) Actually Specified
Need to Get the Dates of All Mondays in a Year
What Makes a Kernel/Os Real-Time
What Does "|" Mean in a Terminal Command Line
How to Erase Printed Characters in a Console Application(Linux)
Is There Any Shortcut to Reference the Path of the First Argument in a Mv Command
Linux - Without Hardware Soundcard, Capture Audio Playback, and Record It to File
Dynamically Determining Where a Rogue Avx-512 Instruction Is Executing