Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/328.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 我的代码给出了一个“;TypeError:并非所有参数都在字符串格式化过程中转换;什么';怎么了?_Python - Fatal编程技术网

Python 我的代码给出了一个“;TypeError:并非所有参数都在字符串格式化过程中转换;什么';怎么了?

Python 我的代码给出了一个“;TypeError:并非所有参数都在字符串格式化过程中转换;什么';怎么了?,python,Python,代码如下: from bs4 import BeautifulSoup import requests x = 0 value = 1 x = x + value url = "https://www.bol.com/nl/s/algemeen/zoekresultaten/sc/media_all/index.html?" + "page=%s" + "&searchtext=ipad" % x response = reque

代码如下:

    from bs4 import BeautifulSoup
    import requests

    x = 0
    value = 1
    x = x + value
    url = "https://www.bol.com/nl/s/algemeen/zoekresultaten/sc/media_all/index.html?" + "page=%s" + "&searchtext=ipad" % x
    response = requests.get(url)
    html = response.text

    soup = BeautifulSoup(html, "lxml")
    letters = soup.find_all("a", "product-title")

    for a in letters:
        title = a.get_text()
        print(title)
它给了我这个错误:

第7行,在 url=“?”+”页面=%s“+”&searchtext=ipad”%x TypeError:在字符串格式化过程中并非所有参数都已转换


我想用这行代码刮去所有网页。

字符串插值应用于错误的字符串(插值发生在串联之前)

要解决此问题,请将其更改为:

"https://www.bol.com/nl/s/algemeen/zoekresultaten/sc/media_all/index.html?" + "page=%s" % x + "&searchtext=ipad"

字符串插值应用于错误的字符串(插值发生在串联之前)

要解决此问题,请将其更改为:

"https://www.bol.com/nl/s/algemeen/zoekresultaten/sc/media_all/index.html?" + "page=%s" % x + "&searchtext=ipad"

另一种方法是将字符串用括号括起来,然后在此括号上进行字符串连接:

url = ("https://www.bol.com/nl/s/algemeen/zoekresultaten/sc/media_all/index.html?" +
       "page=%s" +
       "&searchtext=ipad") % x

这样做的一个优点是,您可以利用括号来表示长线。

另一种方法是将字符串用括号括起来,然后在此括号上进行字符串连接:

url = ("https://www.bol.com/nl/s/algemeen/zoekresultaten/sc/media_all/index.html?" +
       "page=%s" +
       "&searchtext=ipad") % x

这样做的一个好处是,您可以利用括号来表示长线。

在url末尾,有%x个外部引号。不应该用引号括起来吗?在url的末尾,有%x个外部引号。不应该用引号吗?