skip to Main Content

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

2

Answers


  1. 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.

    P.S. 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.

    Login or Signup to reply.
  2. 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 "%sn" "$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 "%sn" "$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 "%sn" "$title"
    

    The use of the REST API sounds a better idea.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search