質問

Im trying to fill out the 'form' on the twitter search home page (link in the code defined as $url) its very basic a box for what you want to search and a search button. But its giving me a lot of difficulty, I cant seem to get it to work. Here is the portion of my script where i'm filling out the 'form'

my $mech = WWW::Mechanize->new();

my $url = "https://twitter.com/search-home";

blah. blah. blah.

$mech->get($url);
$mech->submit_form(
    form_number=> 1,
    fields => {
    query => $tweetsearch,
    button => "Search",
    }
);

print $mech->uri();

When it prints it, it prints out $url meaning it didnt do anything where it should print https://twitter.com/searchsrc=typd&q=from%3Anikestore%20%22jordan%22%20%22concord%22%20%22now%20available%22%20since%3A2014-5-2 Any help?

役に立ちましたか?

解決

You're using wrong form:

$mech->submit_form(
    form_id => "search-home-form",
    fields  => {

        q => "#YourTimeHasCome #MVP #NBA2K15",
    },
);

他のヒント

Like many modern websites, Twitter tends to make heavy use of JavaScript.

From the WWW::Mechanize documentation:

Please note that Mech does NOT support JavaScript, you need additional software for that. Please check "JavaScript" in WWW::Mechanize::FAQ for more.

The FAQ entry mentions these other modules which may have better JS support:

Many websites also offer computer-friendly APIs. Here is Twitter's API documentation.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top