ページ上のすべての URL を取得する必要がある作業を行っています。microsoft.com など、私がテストしたほとんどの Web サイトで動作するようですが、google.com からは 3 つしか返されません。関連するソースコードは次のとおりです。
import urllib
import time
import re
fwcURL = "http://www.microsoft.com" #URL to read
mylines = urllib.urlopen(fwcURL).readlines()
print "Found URLs:"
time.sleep(1) #Pause execution for a bit
for item in mylines:
if "http://" in item.lower(): #For http
print item[item.index("http://"):].split("'")[0].split('"')[0] # Remove ' and " from the end, for example in href=
if "https://" in item.lower(): #For https
print item[item.index("https://"):].split("'")[0].split('"')[0] # Ditto
私のコードを改善できる場合、またはこれを行うためのより良い方法がある場合は、返信してください。前もって感謝します!