Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将单词或URL端点从文件添加到由URL组成的另一个文件_Python 3.x_Url_Url Rewriting_Python Requests - Fatal编程技术网

Python 3.x 将单词或URL端点从文件添加到由URL组成的另一个文件

Python 3.x 将单词或URL端点从文件添加到由URL组成的另一个文件,python-3.x,url,url-rewriting,python-requests,Python 3.x,Url,Url Rewriting,Python Requests,因此,基本上假设我有一个url列表,如: https://google.com/ https://store.google.com/ https://gmail.google.com/ 我还有另一个端点列表: ./endpoint ./path/endpoint ../../../path/endpoint endPoints = ['endpoint1','endpoint2','endPoint3'] 我想要的是: https://google.com/endpoint https:/

因此,基本上假设我有一个url列表,如:

https://google.com/
https://store.google.com/
https://gmail.google.com/
我还有另一个端点列表:

./endpoint
./path/endpoint
../../../path/endpoint
endPoints = ['endpoint1','endpoint2','endPoint3']
我想要的是:

https://google.com/endpoint
https://store.google.com/path/endpoint
https://gmail.google.com/path/endpoint
然后提出请求

我的名单要大得多,数以千计。但我试图完成的是获取端点列表,并在其中循环,将它们附加到URL列表中。返回状态代码、标题等。一旦它在整个列表中循环,就转到下一个列表。我根本不会写代码,但我正在学习。
谁能给我指出正确的方向,或者删除一些能给我灵感的链接。我仍在努力学习如何为“r+”打开一个文件(url列表),返回一行,将另一个文件(端点)作为“r+”打开,将单词附加到url中,等等。在我的新手技能水平上,我似乎有些不知所措,但这是我必须完成的事情。

我假设您的url在列表中
url
,如下所示

urls = ['https://google.com/','https://store.google.com/','https://gmail.google.com/']
然后您可以有一个端点列表:

./endpoint
./path/endpoint
../../../path/endpoint
endPoints = ['endpoint1','endpoint2','endPoint3']
现在,为了创建URL,您可以循环浏览这两个列表,附加URL和端点,并保存相应生成的输出:

mp = dict()
for url in urls:
    for endPoint in endPoints:
        totalUrl = url+endPoint
        mp[totalUrl] = request.get(totalUrl)

现在您可以迭代dict,并相应地使用request对象

url和端点都位于两个sperate文件中。每个列表中至少有1000个。是的,这是一个列表,但它的格式不是你写的那样。或者python将以这种方式解释文件中的列表。该文件是一个列表(url+\n指向文件末尾的所有文件)。不过,你的回答确实给了我一个想法。因为正如我在问题中所说,我想将所有内点附加到列表中的一个url,返回数据,然后移动到列表中的下一个url,直到url用完为止。你知道,不了解太多蟒蛇是很难的。我选择边学边写。到目前为止,我已经删除了两条评论,因为当按enter键转到新行时,它只保存编辑。所以我使用了您提供的代码,但请求失败,所以我决定打印totalUrl。主url位于一行上,端点位于换行符上,因此请求显然是错误的。看起来像这样/suggestAlternatives.js