Run curl command on each line of a file and fetch data from result

aelor

Suppose I have a file containing a list of links of webpages.

www.xyz.com/asdd
www.wer.com/asdas
www.asdas.com/asd
www.asd.com/asdas

I know that doing curl www.xyz.com/asdd will fetch me the html of that webpage. I want to fetch some data from that webpage.

So the scenario is use curl to hit all the links in the file one by one and extract some data from the webpage and store somewhere else. Any ideas or suggestions.

fedorqui 'SO stop harming'

As indicated in the comments, this will loop through your_file and curl each line:

while IFS= read -r line
do
   curl "$line"
done < your_file

To get the <title> of a page, you can grep something like this:

grep -iPo '(?<=<title>).*(?=</title>)' file

So all together you could do

while IFS= read -r line
do
   curl -s "$line" | grep -Po '(?<=<title>).*(?=</title>)'
done < your_file

Note curl -s is for silent mode. See an example with google page:

$ curl -s http://www.google.com | grep -Po '(?<=<title>).*(?=</title>)'
302 Moved

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Each line from file as variable & run command with these variables

Run a command line command from a file

How I can run NUnit from command line and get xml result file?

php curl gives different result than from command line

Run a command for each element in an array from a file

Run php File in Browser from Command Line

Run arangodb text file from command line

VirtualBox - run an ova file from command line

Run command line program from php file

Trying to run cURL from command line (xampp/windows environment)

output redirection when looping over a file to run a command for each line

How do you run a command for each line of a file?

Source a file inside golang and run a command before each listed line

Read and run different command based on each line of file in Bash Linux?

Run wget command on each line of a file and download the files (two at a time)

Fetch source file from GitHub using command line tools?

CURL command line tool - Delete File from FTP server

Run python, with a parameter, on a cURL command on one line

cURL http post file upload using curl --data in linux command line

Execute command on each line in a file

import data from into elasticsearch index using json file and curl command

curl command to upload data from a file to couchbase bucket

Command to remove a portion of JSON data from each line?

Command to keep only a portion of JSON data from each line?

How to run .js file from a command line on windows?

How can I run a ruby file in command line from Java?

How to run a test class in a jar file from command line?

how to run a django python file from command line

Run pdb from command line on application packaged as a zip file?