本文介绍了访问在python bs中通过url传递的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在抓取一个网站,但遇到了一个我无法解决的问题.

I am scraping a website and have come across an issue I can not figure out.

我已经从网站中提取了以下数据:

I have extracted the following data from the site:

```
   tmp = ['/gourl/2aae9bb244631cf75ac56f4f61384c2dcda0d0e9?redirect=http%3A%2F%2Fwww.facebook.com%2F234343435'] 
```

如何保存 ?redirect 的结果.

How can I save the results of ?redirect.

我已经试过了:

    ```
link = re.search("?redirect=", tmp)
    ```

它不起作用.

推荐答案

# python3

import urllib.parse

tmp = [
    "/gourl/2aae9bb244631cf75ac56f4f61384c2dcda0d0e9?redirect=http%3A%2F%2Fwww.facebook.com%2F234343435"
]

for el in tmp:
    url = el.split("?redirect=")[1]
    url_decoded = urllib.parse.unquote(url)
    print(url_decoded)

结果:http://www.facebook.com/234343435

这篇关于访问在python bs中通过url传递的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 07:18