Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/309.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 如何使用请求模块从div获取文本?_Python_Python 3.x_Request - Fatal编程技术网

Python 如何使用请求模块从div获取文本?

Python 如何使用请求模块从div获取文本?,python,python-3.x,request,Python,Python 3.x,Request,问题是我无法理解如何从div中获取文本(比如div的文本)。 这是我的代码: soup = BeautifulSoup(plain_text,features="html.parser") for link in soup.findAll('div',{'class':'item-sub-info'}): value = link.get('dont_know_what_to_write') print(value) 这就是信息: <div class

问题是我无法理解如何从div中获取文本(比如div的文本)。 这是我的代码:

 soup = BeautifulSoup(plain_text,features="html.parser")
 for link in soup.findAll('div',{'class':'item-sub-info'}):
        value = link.get('dont_know_what_to_write')
        print(value)
这就是信息:

<div class="item-sub-info" style="border-right: 5px solid crimson
!important;">              
  **Factory New /
  Covert Knife**
  / <span class="poptip" data-toggle="tooltip" title=""...></div>

**新工厂/
暗刀**
/ 

我需要使用link.get(??)中的未知参数从中获取工厂新/隐蔽刀。应该是什么?

你试过.text吗?@Chris如果我写这个:value=link.get('.text')或value=link.get('text')我刚得到的行是写“无”的可能试着打印(link.text)@Chris是的,我知道它是有效的。没有我想要的使用get的方式,但仍然…您应该查看BeautifulSoup文档。我认为你的问题与请求模块无关。我认为@Lolkek2281337解决方案应该有效。你也可以看看