【问题标题】:Loop through url's without a wildcard不带通配符的 url 循环
【发布时间】:2021-11-24 23:07:15
【问题描述】:

我对此感到困惑。Python 代码用于使用通配符* 循环遍历 url,该通配符仅替换每个匹配项的唯一 ID。这个 url 模式http://www.sportal.de/fussball/bundesliga/spielernoten-bayern-muenchen-fc-schalke-04-1-spieltag-2020-2021-20138500 的问题在于,要使用通配符的文本位于 url 的不变部分和 id 之间。我是编码宇宙的新手,非常感谢任何帮助。完整代码为here

from time import sleep
from datetime import datetime
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import pandas as pd

errors = []
season = []
for id in range(20138500, 20138501):
    # Opening the connection and grabbing the page
    my_url = f'http://www.sportal.de/fussball/bundesliga/spielernoten*{id}'
    option = Options()
    option.headless = False
    driver = webdriver.Firefox(options=option)
    driver.get(my_url)

【问题讨论】:

    标签: python selenium url wildcard


    【解决方案1】:

    浏览器应该知道确切的 URL。您必须指定整个网址

     my_url ="http://www.sportal.de/fussball/bundesliga/spielernoten-bayern-muenchen-fc-schalke-04-1-spieltag-2020-2021-"+str(id)
    

    【讨论】:

      猜你喜欢
      • 2013-11-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-09
      • 2012-05-10
      • 2016-06-05
      • 1970-01-01
      • 2013-04-03
      相关资源
      最近更新 更多