【问题标题】:Need help parsing manga images using BeautifulSoup/requests需要帮助使用 BeautifulSoup/requests 解析漫画图像
【发布时间】:2018-10-12 18:18:04
【问题描述】:

我是 Python 的初学者,我已经学习了该程序的大部分基础知识。所以我决定创建我的第一个项目来测试我的技能和理解力。我的项目涉及从名为https://bato.to/ 的网站解析某个漫画章节的图像。在查看 html 代码时,我注意到图像代码是隐藏的,并且是以我从未见过的格式放置的。

</script>

<script>
var seriesId = 69462;
var chapterId = 1204541;
var images = {"1":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/57a04a3ce55bd48debf0a486a4c1a48f6380ef9b_1066291_800_1138.png","2":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/a0f75d10919430e6ef25a86c3dcc65f343d8e319_518773_800_1138.png","3":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/575d00ff9ef6873ee9ecfb418e360fe72cc1c594_418309_800_1138.png","4":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/cf839d2425379267218aa666d655e78bd0ee4e4a_425299_800_1138.png","5":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/99e371b684dafca9a91b0a7ad447f51582640bfa_480515_800_1138.png","6":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/7780852155c02e4e6b5059beb97131788274c561_614212_800_1138.png","7":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/569b810f952dd3146c7f120d23b24ee7c9707486_548081_800_1138.png","8":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/53d251f743b61863d6d7557844b34ff5152e1609_484778_800_1138.png","9":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/7800fbe47802269e499b2f70fe53b41a52b0594b_410873_800_1138.png","10":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/3583ca41d7ff56641fae4a717e9b612c1ac365f2_436785_800_1138.png","11":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/81eac44fa63bdbdf2e0d29163ff56d79bc71c820_389040_800_1138.png","12":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/b2a0b8833f0002679a06e20f96bcb205306cf903_678271_800_1138.png","13":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/6873e24ba5f0f81b3b86197f99505f4ea04f2ed6_502645_800_1138.png","14":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/6f230cdb1078942871f201f46a7375fdb80c7725_491192_800_1138.png","15":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/b7300babacb6c266c4b01f69cce5178723cacab1_569510_800_1138.png","16":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/5b098d44ddf7e5c859622ca3a0a4b3b73207bf27_617792_800_1138.png","17":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/9acd39d7658b4a1a85b8873d4aa90161d1f43f89_400216_800_1138.png","18":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4e8465f5b2d5051412ccea9dd3b516d37d2f7e78_505009_800_1138.png","19":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/074944985caaa096dc99cf560244ed4f88e7c134_447556_800_1138.png","20":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4e1207273bd67333ab2c498327255725378bff5a_744103_800_1138.png","21":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/b5a3c3ba757be5aaa5bbc5d0c3f563fbb45391f3_444943_800_1138.png","22":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/cb146368fddf4fe9bc80088a5bd5784dd49dfc5a_561421_800_1138.png","23":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/c929cac013ee5b3794600c925850263f54a17a39_488726_800_1138.png","24":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4b8d797546fc185eedcb7efbad5e1e50a4f565cc_479310_800_1138.png","25":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/39c1028bc26adb25171e79b8c739422b8d7c6780_492937_800_1138.png","26":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/e27a386a1f7e95fade1822e5f71dc23797289f08_1069178_1600_1138.png","27":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/51ad85180a93eeb24ea42182c70a45431a483739_504148_800_1138.png","28":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/90b431bfadfe3afd2efa0ab661a1dcda10e309e3_343208_800_1138.png","29":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/48ae08934d842797654822c5535ae7bb132b2643_444143_800_1138.png","30":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/411a7e9fce98275133915a1bfffa4a402dee7b8e_343839_800_1138.png","31":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/614e2cb8de3836b276eb22cdae62ca4c7c6157dd_601185_800_1138.png","32":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/674d038df3e5c9a472a11451ba262eaed67e7390_535795_800_1138.png","33":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d33951612052b7a452e6973b6a2cb5d74210fe05_447169_800_1138.png","34":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/0a6c377f3960ef407ad9ea5c6f46409eb172327c_342094_800_1138.png","35":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d7bfffc6e37d14f4cdd9a6f085355427cd86c3e9_414864_800_1138.png","36":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/87e86923d96455e89e8e3138b3ab5992df17cc79_541358_800_1138.png","37":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/f1c2fe8001425d88e9700633a7891f0901872f55_135829_800_1138.png","38":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/7cd38bb71e091a66c75c2b8a8d05822571c1428b_560422_800_1138.png","39":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/8f6c69eeba0f1f153153d789985dae5b20ee384f_691293_800_1138.png","40":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/ad062d6080615fb08ae2e0d2f8ed092cc3223620_602280_800_1138.png","41":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/5be961c28583bb1dd92725c7c105a4bcf529cef6_484232_800_1138.png","42":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4fdd26894c2a900d4c0cc3ddcf340973419a93a6_533468_800_1138.png","43":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/0ca26c4e3d2d26be25b9bca9b50302ccf1117f80_579802_800_1138.png","44":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/08ce8bbe30f835caa898e6e148e49e1c9b590a8d_603324_800_1138.png","45":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/6dc238a9f03d20f7070d83fd2b2b6d677517c5cf_435471_800_1138.png","46":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/5cd269da6e198133f5da5e9bb125492366df9469_597385_800_1138.png","47":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/c916e3cdeccecfa1cf5b9ae70bdc11a3b20c678f_661926_800_1138.png","48":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/dcc84a86d5379c830f0c0087339cb685ca757999_547146_800_1138.png","49":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/de9b88d1ccfc9acf6a437fff49bf73a535af6370_886149_1600_1138.png","50":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/aa41d6836befb0ae8755c767a892cbfc065223f7_1307106_1600_1138.png","51":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d0320e80cdac4a4e9ac84f920b9b53fb30029b20_478527_800_1138.png","52":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d3c65f840473c8f14de55fda2581e0fa24433410_563860_800_1138.png","53":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/373a7b778e7d335d6d75f611c43559286b3905a0_523659_800_1138.png","54":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/ef7215fe9b2dc00607518a8b14d92e8848ba71b0_507280_800_1138.png","55":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4642779f14b16771af87b63229f15bae9006f4a3_459041_800_1138.png","56":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/db2065e24505b2b3ef633917cca106864aa22baf_436436_800_1138.png","57":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/459f0c4f5359ac0ee516c2175a25ca3c25276cbd_517997_800_1138.png","58":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d489e9dfe04de6f8f5c377b513da55d6a15b59dd_443413_800_1138.png","59":"https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/32b5347b7bd423ab8004c3ef1e5336bc8b13ea3a_368964_800_1138.png"};
var pages = 59;
var page = 0;
var prevCha = {"base":{"uniqueId":1200264,"parentId":0,"seriesId":69462,"createDate":"2018-04-10T06:08:16.041Z","publicDate":"2018-04-10T06:08:16.041Z","modifyDate":null,"updateDate":"2018-04-10T06:08:16.041Z","sortHash":"zzzzz.zzzzz.00090.00000"},"_extra":{"volcha":"Ch.90","updateDateAgo":"22 days ago","updateDateDif":22}};
var nextCha = null;
</script>

我尝试使用 BeautifulSoup 找到 var images 标签来提取带有图像链接的目录,但我无法得到它。我从未使用过“var”标签。 谁能告诉我如何提取var images 标签?
这是我到目前为止编写的代码,但我被卡住了。我不知道如何提取标签。

from bs4 import BeautifulSoup
import requests
import urllib.request, urllib.parse, urllib.error
import json
import os
import re

os.makedirs('OnePunch',exist_ok = True)
# Download the page
url = 'https://bato.to/chapter/1204541.com'
source = requests.get(url).text

print(source)

【问题讨论】:

    标签: python web-scraping beautifulsoup request urllib


    【解决方案1】:

    HTML &lt;script&gt; 元素用于嵌入或引用可执行代码;这通常用于嵌入或引用 JavaScript 代码。

    您抓取的页面由 JavaScript 呈现,初始 HTML 包含一个带有 images 变量的 &lt;script&gt; 标记,其中包含所有图片的 URL。您可以按照Rakesh's 的方法提取包含带有regular expressions 的URL 的JavaScript 对象,或者使用Requests-HTML 在引擎盖下使用Chromium 来呈现在浏览器中显示的网站。

    您可以使用以下代码获取所有网址:

    from requests_html import HTMLSession
    
    session = HTMLSession()
    url = 'https://bato.to/chapter/1204541'
    r = session.get(url)
    r.html.render()
    
    urls = [img.attrs['src'] for img in r.html.find('.item > img')]
    
    >>> urls
    ['https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/57a04a3ce55bd48debf0a486a4c1a48f6380ef9b_1066291_800_1138.png',
     'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/a0f75d10919430e6ef25a86c3dcc65f343d8e319_518773_800_1138.png',
     'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/575d00ff9ef6873ee9ecfb418e360fe72cc1c594_418309_800_1138.png',
     ...
    ]
    
    >>> len(urls)
    59
    

    这个方案的问题是执行时间长。

    为了澄清,.item &gt; img 以所有 img 元素为目标,这些元素是具有 item 类的元素的直接子元素。 您可以阅读有关 CSS 选择器的更多信息here

    你也可以使用Selenium:

    from selenium import webdriver
    
    browser = webdriver.Chrome()
    browser.get(url)
    url_dict = browser.execute_script('return images;')
    browser.quit()
    
    >>> url_dict['1']
    'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/57a04a3ce55bd48debf0a486a4c1a48f6380ef9b_1066291_800_1138.png'
    

    【讨论】:

    • 非常感谢您分享您的答案。我从来不知道 requests_html 模块。看来我还有很长的路要学。由于我熟悉正则表达式,因此我将使用 Rakesh 的答案,但我一定要查看 requests_html 模块文档以了解更多信息。
    • 我尝试使用request_html 方法,但我得到回溯错误:raise MaxRetries("Unable to render the page. Try increasing timeout") requests_html.MaxRetries: Unable to render the page. Try increasing timeout
    • @Blu 尝试设置 timeout 关键字参数,例如:r.html.render(timeout=20)(默认为 8 秒)。老实说,它需要很长时间才能在本网站上显示它几乎不符合此解决方案的资格。即使在我的浏览器中加载也需要 16 秒,所以在这种情况下,如果您不需要 JS 呈现的任何其他数据,则应该使用Rakesh 提出的正则表达式解决方案。
    • 没关系。我将使用硒方法。我现在有理由学习如何使用它。另外,我认为最好避免对 html 使用正则表达式。
    【解决方案2】:

    这应该会有所帮助。

    演示:

    from bs4 import BeautifulSoup
    import requests
    import json
    import os
    import re
    
    # Download the page
    url = 'https://bato.to/chapter/1204541.com'
    source = requests.get(url).text
    soup = BeautifulSoup(source, "html.parser")
    scr = soup.find_all("script")
    pattern = re.compile(r"var\s+images\s+=(.*)")     #Regex to get the script with var images
    
    for i in scr:
        m = pattern.search(i.text)
        if m:
            print(json.loads(m.group(1).replace(";", "")))
    

    输出:

    {u'56': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/db2065e24505b2b3ef633917cca106864aa22baf_436436_800_1138.png', u'54': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/ef7215fe9b2dc00607518a8b14d92e8848ba71b0_507280_800_1138.png', u'42': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4fdd26894c2a900d4c0cc3ddcf340973419a93a6_533468_800_1138.png', u'48': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/dcc84a86d5379c830f0c0087339cb685ca757999_547146_800_1138.png', u'43': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/0ca26c4e3d2d26be25b9bca9b50302ccf1117f80_579802_800_1138.png', u'49': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/de9b88d1ccfc9acf6a437fff49bf73a535af6370_886149_1600_1138.png', u'52': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d3c65f840473c8f14de55fda2581e0fa24433410_563860_800_1138.png', u'53': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/373a7b778e7d335d6d75f611c43559286b3905a0_523659_800_1138.png', u'24': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4b8d797546fc185eedcb7efbad5e1e50a4f565cc_479310_800_1138.png', u'25': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/39c1028bc26adb25171e79b8c739422b8d7c6780_492937_800_1138.png', u'26': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/e27a386a1f7e95fade1822e5f71dc23797289f08_1069178_1600_1138.png', u'27': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/51ad85180a93eeb24ea42182c70a45431a483739_504148_800_1138.png', u'20': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4e1207273bd67333ab2c498327255725378bff5a_744103_800_1138.png', u'21': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/b5a3c3ba757be5aaa5bbc5d0c3f563fbb45391f3_444943_800_1138.png', u'22': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/cb146368fddf4fe9bc80088a5bd5784dd49dfc5a_561421_800_1138.png', u'23': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/c929cac013ee5b3794600c925850263f54a17a39_488726_800_1138.png', u'46': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/5cd269da6e198133f5da5e9bb125492366df9469_597385_800_1138.png', u'47': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/c916e3cdeccecfa1cf5b9ae70bdc11a3b20c678f_661926_800_1138.png', u'44': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/08ce8bbe30f835caa898e6e148e49e1c9b590a8d_603324_800_1138.png', u'45': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/6dc238a9f03d20f7070d83fd2b2b6d677517c5cf_435471_800_1138.png', u'28': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/90b431bfadfe3afd2efa0ab661a1dcda10e309e3_343208_800_1138.png', u'29': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/48ae08934d842797654822c5535ae7bb132b2643_444143_800_1138.png', u'40': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/ad062d6080615fb08ae2e0d2f8ed092cc3223620_602280_800_1138.png', u'41': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/5be961c28583bb1dd92725c7c105a4bcf529cef6_484232_800_1138.png', u'1': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/57a04a3ce55bd48debf0a486a4c1a48f6380ef9b_1066291_800_1138.png', u'3': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/575d00ff9ef6873ee9ecfb418e360fe72cc1c594_418309_800_1138.png', u'2': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/a0f75d10919430e6ef25a86c3dcc65f343d8e319_518773_800_1138.png', u'5': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/99e371b684dafca9a91b0a7ad447f51582640bfa_480515_800_1138.png', u'4': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/cf839d2425379267218aa666d655e78bd0ee4e4a_425299_800_1138.png', u'7': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/569b810f952dd3146c7f120d23b24ee7c9707486_548081_800_1138.png', u'6': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/7780852155c02e4e6b5059beb97131788274c561_614212_800_1138.png', u'9': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/7800fbe47802269e499b2f70fe53b41a52b0594b_410873_800_1138.png', u'8': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/53d251f743b61863d6d7557844b34ff5152e1609_484778_800_1138.png', u'51': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d0320e80cdac4a4e9ac84f920b9b53fb30029b20_478527_800_1138.png', u'39': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/8f6c69eeba0f1f153153d789985dae5b20ee384f_691293_800_1138.png', u'38': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/7cd38bb71e091a66c75c2b8a8d05822571c1428b_560422_800_1138.png', u'59': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/32b5347b7bd423ab8004c3ef1e5336bc8b13ea3a_368964_800_1138.png', u'58': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d489e9dfe04de6f8f5c377b513da55d6a15b59dd_443413_800_1138.png', u'11': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/81eac44fa63bdbdf2e0d29163ff56d79bc71c820_389040_800_1138.png', u'10': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/3583ca41d7ff56641fae4a717e9b612c1ac365f2_436785_800_1138.png', u'13': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/6873e24ba5f0f81b3b86197f99505f4ea04f2ed6_502645_800_1138.png', u'12': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/b2a0b8833f0002679a06e20f96bcb205306cf903_678271_800_1138.png', u'15': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/b7300babacb6c266c4b01f69cce5178723cacab1_569510_800_1138.png', u'14': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/6f230cdb1078942871f201f46a7375fdb80c7725_491192_800_1138.png', u'17': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/9acd39d7658b4a1a85b8873d4aa90161d1f43f89_400216_800_1138.png', u'16': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/5b098d44ddf7e5c859622ca3a0a4b3b73207bf27_617792_800_1138.png', u'19': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/074944985caaa096dc99cf560244ed4f88e7c134_447556_800_1138.png', u'18': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4e8465f5b2d5051412ccea9dd3b516d37d2f7e78_505009_800_1138.png', u'31': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/614e2cb8de3836b276eb22cdae62ca4c7c6157dd_601185_800_1138.png', u'30': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/411a7e9fce98275133915a1bfffa4a402dee7b8e_343839_800_1138.png', u'37': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/f1c2fe8001425d88e9700633a7891f0901872f55_135829_800_1138.png', u'36': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/87e86923d96455e89e8e3138b3ab5992df17cc79_541358_800_1138.png', u'35': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d7bfffc6e37d14f4cdd9a6f085355427cd86c3e9_414864_800_1138.png', u'34': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/0a6c377f3960ef407ad9ea5c6f46409eb172327c_342094_800_1138.png', u'33': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/d33951612052b7a452e6973b6a2cb5d74210fe05_447169_800_1138.png', u'55': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/4642779f14b16771af87b63229f15bae9006f4a3_459041_800_1138.png', u'32': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/674d038df3e5c9a472a11451ba262eaed67e7390_535795_800_1138.png', u'57': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/459f0c4f5359ac0ee516c2175a25ca3c25276cbd_517997_800_1138.png', u'50': u'https://file-comic-99.anyacg.co/uploads/5ae318893532c3405bd86baa/aa41d6836befb0ae8755c767a892cbfc065223f7_1307106_1600_1138.png'}
    

    【讨论】:

    • 哇!!十分感谢你的帮助。你给了我一个关于正则表达式的巨大提示。我被告知永远不要在 html 页面上使用正则表达式。从来不知道有例外。
    • @BluHaz 您应该尽可能避免使用正则表达式。它们可能会变得冗长、过于复杂、难以理解和维护。
    • 好的,明白了。除了 requests_html 之外,还有其他模块可以提供帮助吗?
    • @Blu 你也可以使用Selenium,我用一个解决方案更新了我的答案,但是,我认为如果你想要实现的唯一目标是获取 URL 而不是需要渲染整个页面以抓取任何其他数据。
    猜你喜欢
    • 2018-12-11
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    • 2017-11-03
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多