简体   繁体   中英

Pull information from wget data

I want to pull and display the twitter username of various accounts that I specify via the ID. I figured I could do this, in part, with wget.

echo what id would you like to search
read ID 
wget https://twitter.com/intent/user?user_id=$ID > ~/temp/$ID

This is really as far as I got as I cant figure out how to pull the data from it. I have tried this;

read ID
source ~/temp/$ID
echo $value

To echo anything that was labeled as "value" (the username is labeled as "value" several times).

Examples: Stack Overflow's Twitter account is @stackoverflow, and their twitter id is: 128700677 So I can run

wget https://twitter.com/intent/user?user_id=128700677

and the document will be a nice 248 line long HTML document, you can try it and see. So basically, is there a way to have the script either go through and find the most common value="" or just go to/display <title>Stack Overflow (@StackOverflow) on Twitter</title> without the <title></title> and on Twitter

PS: Would this count as bootstrapping?

EDIT----------------------------- This needs to be able to work with bash because I already have a system set up in bash. This will just help confirm @s

As that-other-guy said, it would be better to use twitter API to find that out. However, you can try and push your method a little bit further, like

wget -O - "https://twitter.com/intent/user?user_id=${ID}" | grep -Po "(?<=screen_name=).*(?=')" | head -n 1

to filter out strings like href='/intent/user?screen_name=StackOverflow' and extract what's after screen_name= part in the first string.

PS I didn't notice a lot of value= in the html, to be honest, and sourcing something like html in your script is not the best thing to do, as you may get something destructive executing this way.

screen_name could be fetched with:

 read -r ID ;\
 screen_name=$(wget -q -O - http://twitter.com/intent/user?user_id="$ID" |  sed -n 's/^.*button follow".*screen_name=\([^"]*\)".*$/\1/p')
 printf "%s\n" "$screen_name"

nickname could be fetched with:

read -r ID ;\
nickname=$(wget -q -O - https://twitter.com/intent/user?user_id=128700677 | sed -n 's/^.*"nickname">\([^<]*\)<.*$/\1/p')
printf "%s\n" "$nickname"

title could be fetched with:

read -r ID ;\
title=$(wget -q -O - https://twitter.com/intent/user?user_id=128700677 | sed -n 's/^.*<title>\(.*\) on Twitter<.title>.*$/\1/p')
printf "%s\n" "$title"

The use of the REST API sounds a better idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM