Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.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 如何使用BeautifulSoup从源代码中获取阵列数据?_Python_Django_Beautifulsoup - Fatal编程技术网

Python 如何使用BeautifulSoup从源代码中获取阵列数据?

Python 如何使用BeautifulSoup从源代码中获取阵列数据?,python,django,beautifulsoup,Python,Django,Beautifulsoup,我在这里要做的是处理“=>”之后的值 有可能用BeautifulSoup制作吗 这是源代码中的内容: <!-- <pre style="text-align: left">Array ( [vl_lance_order] => R$ 34.000 [data_leilao] => 17-07-2015 - 10h00 [nm_identificacao] => [incremento_minimo] => 2000 [incremento_siste

我在这里要做的是处理“=>”之后的值 有可能用BeautifulSoup制作吗

这是源代码中的内容:

<!-- <pre style="text-align: left">Array
(
[vl_lance_order] => R$ 34.000
[data_leilao] => 17-07-2015 - 10h00 
[nm_identificacao] => 
[incremento_minimo] => 2000
[incremento_sistema] => 2000.00
[mensagem] => FOTOS ATUALIZADAS
[segmento_id] => 667740
[dt_inicioleilaoonline] => 2015-07-13
[nm_img] => C667740A.JPG;C667740B.JPG;C667740C.JPG;C667740D.JPG;C667740E.JPG;C667740F.JPG
[nu_contadorvisita] => 921
[vl_multiplo] => 0.00
[ordenacao] => 0
[nm_deposito] => Curitiba
[numlances] => 14
[cli] => 1230
[nm_cliente] => BANCO MERCEDES-BENZ S.A
[link] => /leilao/12240/lote/1485951/segmento/veiculos/ordenacao/data_leilao/tipo-ordenacao/crescente/qtde-itens/15/visualizacao/visual_imagem/item-atual/1/pagina/1/
)
</pre> -->
除使用BeautifulSoup外,欢迎使用其他解决方案。
你为什么不这样做呢

  • 迭代所有行
  • 查找包含
    =>
    符号的行
  • 然后对
    =>
    符号进行拆分,然后打印拆分列表的索引1

如果源代码总是和你提供的形式相同,为什么不考虑把它拆分成几行,然后用<代码>“= >”< /代码>?

url = 'https://www.example.com'
source_code = requests.get(url)
soup = BeautifulSoup(source_code.content, "html5lib")
for line in src.split("\n"):
    segs = line.split("=>")
    if len(segs) == 2:
        key = segs[0].strip().replace("[", "").replace("]", "")
        value = segs[1].strip()