cURL选项 - 会话和cookie(cURL Option - session and cookie)
在脚本中,我使用cURL登录或将一些信息发布到另一个站点。
当用户加载此脚本时,我们没有任何问题,但是当两个用户同时加载脚本时,另一个站点加载第一页,因为我们的主机中的cookie为一个用户设置,并且该站点从用户获得两个不同的命令。
如果为该站点为每个用户获取不同的SESSION和COOKIE的任何用户加载脚本,我该怎么做?
$ch = curl_init(); $agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); $result = curl_exec($ch); return $result;
In a script I used cURL for login or post some information to another site.
When a user loads this script we have not any problem but when two user simultaneously load script the another site loads first page, because the cookie in our host set for one user, and the site get two different commands from a user.
How can I do that when the script was loaded for any user that the site get different SESSION and COOKIE to each user?
$ch = curl_init(); $agent = $_SERVER["HTTP_USER_AGENT"]; curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt'); curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt'); $result = curl_exec($ch); return $result;
原文:https://stackoverflow.com/questions/30583079
最满意答案
根据你的问题,你想比较两个句子,然后可能找出他们匹配的百分比。
要查找句子之间的相似性,您可以使用
Jaccard Similarity
或Cosine Similarity
。请参阅此余弦相似度如何计算2个句子字符串的余弦相似度? - Python
如果余弦相似度小于那么句子也不相似,但如果它更接近1那么句子是相似的
NLTK可用于查找句子中单词的同义词,以便您可以从句子中获取语义。
要查找同义词,您可以使用以下代码:
from nltk.corpus import wordnet as wn wn.synsets(your word)
According to your question you want to compare two sentences and then probably find out how much percentage they match.
For finding the similarity between sentences you can use
Jaccard Similarity
orCosine Similarity
.Refer this for Cosine Similarity How to calculate cosine similarity given 2 sentence strings? - Python
If the cosine similarity is less then the sentences are nor similar but if it is closer to 1 then the sentences are similar
NLTK can be used to find the synonyms of the words in the sentence so that you can get semantics from the sentence.
For finding synonyms you could use the following code:
from nltk.corpus import wordnet as wn wn.synsets(your word)
相关问答
更多-
这将是答案。 即时可用的PHP功能。 This would be the answer. Ready-to-use PHP function.
-
如何最好地匹配两个字符串?(How to best match two strings?)[2022-06-25]
莱文斯坦距离就是这样的一个衡量标准。 它基本上告诉你需要编辑,删除或添加多少个字符,才能从第一个字符串到第二个字符串。 我不确定某些数据库系统是否支持该功能。 但是我确实知道一些名为Soundex的简化算法在某些数据库系统中得到了支持。 The Levenstein distance is such a measure. It basically tells you how many characters need to be edited, deleted or added, to get from th ... -
您正在寻找重叠的正则表达式匹配。 简单地说,使用python中的默认正则表达式引擎并不容易。 但是,您可以使用regex模块(先将pip install )。 调用regex.findall并设置overlapped=True 。 import regex a, b = ' ', '(' text = 'here is an example()' regex.findall('{}(.*?){}'.format(*map(re.escape, (a, b))), text, overlapped=Tr ...
-
根据你的问题,你想比较两个句子,然后可能找出他们匹配的百分比。 要查找句子之间的相似性,您可以使用Jaccard Similarity或Cosine Similarity 。 请参阅此余弦相似度如何计算2个句子字符串的余弦相似度? - Python 如果余弦相似度小于那么句子也不相似,但如果它更接近1那么句子是相似的 NLTK可用于查找句子中单词的同义词,以便您可以从句子中获取语义。 要查找同义词,您可以使用以下代码: from nltk.corpus import wordnet as wn wn.syn ...
-
将两个字符串分配在一起获取Access Read Violation(Assigning two strings together getting Access Read Violation)[2023-03-26]
Currency默认构造函数是: Currency() : _next(NULL), _prev(NULL), _position(0) {} 并且似乎没有为_coin分配任何内存。 您的Exchange::Exchange(std::string str)构造函数也执行: _currencies = new Currency; 它调用Currency的默认构造函数,然后传递给parseTradePairs() ,所以很可能是这一行: curr->_coin->setExch(temp); 因此,我试 ... -
首先,NLTK的word_tokenize()可能不适合您输入的希腊数据; 默认的nltk.tokenize.word_tokenize()在英语Penn nltk.tokenize.word_tokenize()上进行培训,请参阅https://nltk.googlecode.com/svn/trunk/doc/api/nltk.tokenize.treebank.TreebankWordTokenizer-class.html 我不确定你是否得到了正确的标记化,但由于希腊语使用空格作为标记分隔符,NLT ...
-
如何使用NLTK同义词在字符串列表中查找同义词?(How to find a synonyms in a list of strings using NLTK synsets?)[2023-11-29]
您需要单独传递单词而不是在加入单词后传递单词。 from nltk.corpus import wordnet as wn def getSynonyms(word1): synonymList1 = [] for data1 in word1: wordnetSynset1 = wn.synsets(data1) tempList1=[] for synset1 in wordnetSy ... -
Lemmainser使用NLTK(Lemmainser using NLTK)[2022-07-02]
你需要一本字典来将NLTK POS标签翻译成WordNet标签: pos_translate = {'J':'a', 'V':'v', 'N':'n', 'R':'r'} 现在,提取POS标签,翻译每个标签,如果可能的话(如果可能的话,选择一个默认标签,比如说, "n" ,并且引理: text = ['This', 'is', 'a', 'car', '.'] [lemmatizer.lemmatize(w,\ pos=pos_translate[pos[0]] if pos[0] in p ... -
Nltk导入问题(Nltk import problems)[2022-09-22]
从解释器中输入 import nltk import sys print(nltk) print(sys.executable) 然后创建一个具有相同内容的脚本并运行 python script.py 请发布输出。 From the interpreter, type import nltk import sys print(nltk) print(sys.executable) and then create a script with the same contents and run pytho ... -
在EdChums上建立评论这里是一种从CountVectorizer获得(我假设全局)字数的方法: import pandas as pd from sklearn.feature_extraction.text import CountVectorizer vect= CountVectorizer() df= pd.DataFrame({'text':['cat on the cat','angel eyes has','blue red angel','one two blue','blue wha ...