【问题标题】:Scrapy python change urlScrapy python更改网址
【发布时间】:2014-05-31 12:48:17
【问题描述】:

我正在尝试收集有关医生的信息。我有以下 url,但我想继续更改 url 的 UserID=99 并保存信息。我不知道如何放置诸如循环之类的东西,该循环不断更改 url 中的用户 ID 以及何时更改 scrapy crawl sch -o items.json -t json 它将所有内容保存到一个 JSON 文件中。

class DmozSpider(Spider):
    name = "sch"
    allowed_domains = ["qchp.org.qa/en/"]
    start_urls = [
        "http://www.qchp.org.qa/en/_layouts/SCH_Website/PractitionerDetails.aspx?UserID=990&IsDlg=1"
    ]

【问题讨论】:

    标签: python json scrapy


    【解决方案1】:

    假设您想用从1100 的奇数代替UserID=990。然后做:

    start_urls = []
    
    for i in range(1, 100):
        if i % 2 == 1:
            start_urls.append("http://www.qchp.org.qa/en/_layouts/SCH_Website/PractitionerDetails.aspx?UserID=" + str(i) + "&IsDlg=1")
    

    【讨论】:

    • 我得到 TypeError: cannot concatenate 'str' and 'int' objects
    • 非常感谢。我刚做了 str(i)。
    猜你喜欢
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 2011-09-17
    • 2012-01-22
    • 2022-11-08
    • 2011-08-27
    • 2015-03-04
    相关资源
    最近更新 更多