Python 3.x 使用粗糙脚本时遇到问题(选择链接)

Python 3.x 使用粗糙脚本时遇到问题(选择链接),python-3.x,xpath,scrapy,pycharm,Python 3.x,Xpath,Scrapy,Pycharm,我正在使用Scrapy,脚本有问题。它与外壳配合良好: scrapyshell“www.redact.com”我使用response.xpath(“//li[@a data-urltype()”)。extract 我能够刮200左右的网页链接 以下是我试图从网页中获取的代码: <a data-urltype="/view" data-mce-href="http://www.redacted.aspx?ID=xxxxxxxxxx" data-linktype="external" href

我正在使用Scrapy,脚本有问题。它与外壳配合良好:

scrapyshell“www.redact.com”
我使用
response.xpath(“//li[@a data-urltype()”)。extract

我能够刮200左右的网页链接

以下是我试图从网页中获取的代码:

<a data-urltype="/view" data-mce-href="http://www.redacted.aspx?ID=xxxxxxxxxx" data-linktype="external" href="http://www.redacted.com/Home/wfContent.aspx?xxxxxxxxxxxxx" data-val="http://www.redacted.gov/Home/wfContent.aspx?xxxxxxxxxxxx" target="_blank">link text</a>    

如果要从
a
中刮取
数据val
。使用下面的xpath

  links = response.xpath("//li/a/@data-val").xpath.extract()

您不需要使用
.xpath()
两次:

links = response.xpath("//li/a/@data-val").extract()
# or
links = response.xpath("//li/a/@data-val").getall()
下面的内容也没有意义(可能是您需要
来获取链接中的链接
?):


@DisplayName,太好了,你接受这个答案,别忘了点击检查按钮。谢谢。谢谢,我是新来的,让我找一下按钮。
links = response.xpath("//li/a/@data-val").extract()
# or
links = response.xpath("//li/a/@data-val").getall()
for links in links:
    items['links'] = links

    yield{
        'links': links
    }