我正在尝试从此 html 中提取公司名称、公司地址和公司编号
<div class="companyInformation">
<p class="contentTitle">
<a itemprop="CompanyName" href='/companies/toshio-s-pte-ltd/'>
Toshio (S) Pte Ltd
</a>
<input type="hidden" name="data_BasicListings$ctl05$hidBasicComNo" id="data_BasicListings_ctl05_hidBasicComNo" value="T591107709" />
</p>
<p class="address" itemprop="CompanyAddress">
629 Aljunied Rd #08-13 Cititech Ind Bldg S(389838)
</p>
<div class="spriteBtn">
<div class="greyBg">
<span style="display: ">
<a class="phoneBtn" title='+65 67431383#toshio-s-pte-ltd'
href="#"><span class="phoneLabel">CALL NOW</span> <span class="phoneNum">
+65 67431383
</span></a></span><span itemprop="Email" style="display: none">
<a href='/companies/toshio-s-pte-ltd/#enquiryForm'
class="enquireBtn"></a></span>
</div>
<span itemprop="Website" style="display: none">
<a rel="nofollow" href='/companies/toshio-s-pte-ltd/'
class="websiteBtn">Home Page</a></span> <span><a class="locationBtn" id='vmap_bs_5'
target="_blank" rel="nofollow" onclick="_gaq.push(['_trackEvent','Search_Results_Google_Map_Click','click','toshio-s-pte-ltd'])">
View Map</a></span>
</div>
</div>
我通过编写这个 xpath 表达式到达这个节点:
hxs=HtmlXPathSelector(response)
names = hxs.select("//div[@class='companyInformation']")
然后我尝试通过以下方式提取公司名称
item["name"]=names.select("a/@itemprop='CompanyName'").extract()
这是我的全部代码
from scrapy.spider import BaseSpider
from scrapy.selector import HtmlXPathSelector
from greenbook.items import GreenbookItem
class MySpider(BaseSpider):
name = "greenbook"
#allowed_domains = ["craigslist.org"]
start_urls = ["http://www.thegreenbook.com/products/absorbers-grease-oil/"]
def parse(self, response):
hxs=HtmlXPathSelector(response)
names = hxs.select("//div[@class='companyInformation']")
items=[]
for names in names:
item = GreenbookItem()
item["name"]=names.select("a/@itemprop='CompanyName'").extract()
items.append(item)
return item
我目前没有提取任何东西,有人可以帮助我吗?我需要提取公司名称