Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/apache-spark/5.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
如何捕获实时请求url';使用python,使用selenium将_Python_Python 3.x_Selenium_Selenium Webdriver_Request - Fatal编程技术网

如何捕获实时请求url';使用python,使用selenium将

如何捕获实时请求url';使用python,使用selenium将,python,python-3.x,selenium,selenium-webdriver,request,Python,Python 3.x,Selenium,Selenium Webdriver,Request,我设置了一个selenium脚本来打开一个特定的网站,该网站每30秒请求多个URL,我需要以某种方式捕获这些请求的URL,并将它们复制到我电脑上的本地文件中 我在谷歌上做了很多搜索,发现有人推荐browsermob proxy,但它似乎不适合我的需要,因为我需要实时将URL写入文件。我将在chrome的NetworkDeveloper工具中给出一张我所说的需要复制到文件中的示例照片 这应该有助于你: from selenium import webdriver import copy impor

我设置了一个selenium脚本来打开一个特定的网站,该网站每30秒请求多个URL,我需要以某种方式捕获这些请求的URL,并将它们复制到我电脑上的本地文件中

我在谷歌上做了很多搜索,发现有人推荐browsermob proxy,但它似乎不适合我的需要,因为我需要实时将URL写入文件。我将在chrome的NetworkDeveloper工具中给出一张我所说的需要复制到文件中的示例照片

这应该有助于你:

from selenium import webdriver
import copy
import threading

global driver
    
def retrieve_urls():    
    
    threading.Timer(30, retrieve_urls).start() #Repeats the task every 30 seconds
    
    driver.get('webpage url') #Enter the url of the webpage here
    
    urls = driver.find_elements_by_class_name('pull-left epnlink')
    
    url_list = []
    
    for element in urls:
        url_list.append(element.get_attribute('href'))

    path = "Urls.txt" #Enter the path of the text file here
    
    f = open(path,'r')
    
    txt = f.readlines()
    
    f.close()
    
    for x in range(len(txt)):
        txt[x] = txt[x].strip()
    
    final_txt = ""
    
    f = open(path,'w')
    
    dup = copy.deepcopy(url_list)
    
    for x in dup:
        if x not in txt:
            final_txt += x + "\n"
            url_list.remove(x)
    
    for x in url_list:
        final_txt += x + "\n"
    
    f.write(final_txt)        
    
    f.close()

driver = webdriver.Chrome()

retrieve_urls()

如果你有任何错误,请告诉我。这可能是因为我没有测试我的程序(因为我在这个网站上没有帐户)。但我希望这能起作用。

到目前为止,你的代码是什么?这是非常基本的,不需要发布。它只需进入网站并登录,然后进入需要等待的页面(它每30秒发布一次链接的页面)。我只需要弄清楚如何捕获在页面上滚动的链接。好的……那么如果你提供网页的链接会有所帮助。哦,是的,我忘了它是itemalert.com。它提供了一个新的易趣项目,适合你保存的搜索确定……链接在哪里弹出?我应该注册查看链接吗?哦,哇,非常感谢,这正是我所希望的!来自我这边的一个谦虚的请求。当你达到10%时,你能投票支持我的答案吗?这对我来说意义重大。谢谢!给你寿司。