Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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
Html Web抓取标题属性的内容_Html_Python 3.x_Web - Fatal编程技术网

Html Web抓取标题属性的内容

Html Web抓取标题属性的内容,html,python-3.x,web,Html,Python 3.x,Web,我跟随一个关于如何使用BeautifulSoup编程web刮板的教程 这是一个带有时间戳的教程 一切进展顺利,我设法得到了品牌名称并将其保存到一个变量中 然而,当谈到获取项目名称时,我不知道我是否偏离了教程,或者网站的结构是否发生了变化,但我无法做到这一点 这是我的密码: from urllib.request import urlopen as uReq from bs4 import BeautifulSoup as Soup my_url = 'https://www.newegg.c

我跟随一个关于如何使用BeautifulSoup编程web刮板的教程

这是一个带有时间戳的教程

一切进展顺利,我设法得到了品牌名称并将其保存到一个变量中

然而,当谈到获取项目名称时,我不知道我是否偏离了教程,或者网站的结构是否发生了变化,但我无法做到这一点

这是我的密码:

from urllib.request import urlopen as uReq
from bs4 import BeautifulSoup as Soup 

my_url = 'https://www.newegg.com/global/uk-en/Desktop-Graphics-Cards/SubCategory/ID-48?nm_mc=KNC-GoogleukAdwords&cm_mmc=KNC-GoogleukAdwords-_-Sitelink-UK-_-VGA-Cards-_-Global&gclid=CjwKCAjwv4_1BRAhEiwAtMDLsjTOkmeuVkXvw4LI45DrrqAEHdpSjqAgYEhh48TO-7kGQiAe0x5VPBoCBYQQAvD_BwE'


#Opening conection, grabbing page
uClient = uReq(my_url)

#offloads contents into variable
page_html = uClient.read()

#closes connection
uClient.close()

#html parsing
page_soup = Soup(page_html, "html.parser")

#grabs each product
containers = page_soup.findAll("div", {"class": "item-container"})




divWithInfo = containers[0].find("a","item-title")

如果我在何处打印divWithInfo的内容,我将获得:

这是我所能做到的。我读了这篇文章,并假设我需要在标签中搜索title属性。但是,我不知道如何将title属性的内容打印到变量

最终结果是能够只打印项目名称,因此:
“GIGABYTE Radeon RX 570 DirectX 12 GV-RX570GAMING-4GD REV2.0 4GB 256位GDDR5 PCI Express 3.0 x16 ATX视频卡”


我对这一切都很陌生,如果有任何需要澄清的地方,我将非常感谢您的帮助。请告诉我。

您只需要获取文本即可。这可以相当简单地做到:

divWithInfo = containers[0].find("a","item-title").get_text()


你只需要得到文本。这可以相当简单地做到:

divWithInfo = containers[0].find("a","item-title").get_text()


谢谢,我知道这听起来很琐碎,但我花了两个小时试图自己解决这个问题。我真的很感激!没问题!很高兴我能帮忙!谢谢,我知道这听起来很琐碎,但我花了两个小时试图自己解决这个问题。我真的很感激!没问题!很高兴我能帮忙!