Wget recognizes some part of my URL address as a syntax error
Asked Answered
H

3

5

I am quite new with wget and I have done my research on Google but I found no clue.

I need to save a single HTML file of a webpage:

wget yahoo.com -O test.html

and it works, but, when I try to be more specific:

wget http://search.yahoo.com/404handler?src=search&p=food+delicious -O test.html

here comes the problem, wget recognizes &p=food+delicious as a syntax, it says: 'p' is not recognized as an internal or external command

How can I solve this problem? I really appreciate your suggestions.

Hitandrun answered 11/4, 2011 at 18:11 Comment(2)
what u want to do? whats the purpose?Lungki
i want a search engine to count how many hits does my keyword have, so i simply make a URL that contains my keyword in it, but the problem comes as wget recognize soome part of my URL address as a syntax errorHitandrun
P
16

The & has a special meaning in the shell. Escape it with \ or put the url in quotes to avoid this problem.

wget http://search.yahoo.com/404handler?src=search\&p=food+delicious -O test.html

or

wget "http://search.yahoo.com/404handler?src=search&p=food+delicious" -O test.html

In many Unix shells, putting an & after a command causes it to be executed in the background.

Poppo answered 11/4, 2011 at 18:13 Comment(5)
To clarify, this has nothing to do with wget. The special meaning of & is interpreted (by bash, sh, or whatever) before it gets to wget.Poi
actually i am running wget on windows, and i have tried your suggestions, but none of the works, when i tried this : wget search.yahoo.com/404handler?src=search\&p=food+delicious -O test.html it gives the same error message, when i tried this: wget "search.yahoo.com/404handler?src=search&p=food+delicious" -O test.html it goes: error 404: Not FoundHitandrun
The 404 you get is a problem with the url (notice the /404handler?... part?) . http://search.yahoo.com/search?p=food+delicious seems to work better, but you should really research how interaction with Yahoo search should be scripted.Poppo
Single quotes did not work for me but scape the & with \ made the affair for meAiaia
the second option is awesome :DSaldana
O
9

Wrap your URL in single quotes to avoid this issue.

i.e.

wget 'http://search.yahoo.com/404handler?src=search&p=food+delicious' -O test.html
Olethea answered 11/4, 2011 at 18:16 Comment(1)
i have tried your suggestion but it doesn't work, it goes: 'error 404: Not found'Hitandrun
A
0

if you are using a jubyter notebook, maybe check if you have downloaded

pip install wget 

before warping from URL

Allman answered 9/8, 2022 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.