diff options
author | emkael <emkael@tlen.pl> | 2019-01-31 21:09:58 +0100 |
---|---|---|
committer | emkael <emkael@tlen.pl> | 2019-01-31 21:09:58 +0100 |
commit | e1056ce60855b0a6ece9f49ae5b96b6c9c52ab08 (patch) | |
tree | 79e175ffe58a394bde6e130f4cbec27854dbb2de | |
parent | aa19ac70447506b64c78ab38a6a3031f7effa31a (diff) |
Reading HtmlFeed user agent from config file
-rwxr-xr-x | bin/get-user-agent.sh | 10 | ||||
-rw-r--r-- | providers/HtmlFeed.php | 8 |
2 files changed, 15 insertions, 3 deletions
diff --git a/bin/get-user-agent.sh b/bin/get-user-agent.sh new file mode 100755 index 0000000..4d348d9 --- /dev/null +++ b/bin/get-user-agent.sh @@ -0,0 +1,10 @@ +#!/bin/bash +ACCESSLOG="$1" +PATTERN="$2" +OUTPUT="$3" +LINE=`grep "$PATTERN" "$ACCESSLOG" | grep Chrome | tail -n 1` +if [ -n "$LINE" ] +then + COLS=`echo "$LINE" | csvtool -t ' ' width -` + echo "$LINE" | csvtool -t ' ' col $COLS - | sed 's/"//g' > $OUTPUT +fi diff --git a/providers/HtmlFeed.php b/providers/HtmlFeed.php index 411cddf..64d6259 100644 --- a/providers/HtmlFeed.php +++ b/providers/HtmlFeed.php @@ -7,10 +7,12 @@ require_once('../lib/querypath/src/qp.php'); abstract class HtmlFeed extends \Providers\XmlFeed { - const HTML_FEED_USER_AGENT = 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11 (.NET CLR 3.5.30729)'; - private $_encoding; + private function __getUserAgent() { + return trim(file_get_contents('../config/user-agent')); + } + private function __getHttpContent($feedUrl) { $header = array(); $header[] = 'Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5'; @@ -20,7 +22,7 @@ abstract class HtmlFeed extends \Providers\XmlFeed { $header[] = 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7'; $header[] = 'Pragma: '; $ch = curl_init($feedUrl); - curl_setopt($ch, CURLOPT_USERAGENT, self::HTML_FEED_USER_AGENT); + curl_setopt($ch, CURLOPT_USERAGENT, $this->__getUserAgent()); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_AUTOREFERER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |